package com.photoeditor.demo.ui.widget.image.edit;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.gpuimage.AdjustGPUImageView;
import com.android.gpuimage.EnLargerFilter;
import com.android.gpuimage.GPUImageFilter;
import com.android.gpuimage.GPUImageToneCurveFilter;
import com.android.gpuimage.GPUImageWhiteBalanceAndToneCurveFilter;
import com.android.gpuimage.GPUImageWhiteBalanceFilter;
import com.android.gpuimage.TwinEnLargerFilter;
import com.android.graffiti.IndicativeHorizontalScrollView;
import com.common.base.utils.DeviceUtils;
import com.common.base.utils.thread.ThreadPool;
import com.photoeditor.R;
import com.photoeditor.demo.model.image.beauty.BeautifyMultiThread;
import com.photoeditor.demo.model.image.collage.templet.BgBean;
import com.photoeditor.demo.model.image.util.ImageHelper;
import com.photoeditor.demo.model.preference.SPDataManager;
import com.photoeditor.demo.model.store.module.HomeOnlineConfig;
import com.photoeditor.demo.model.store.module.StoreOnlineBean;
import com.photoeditor.demo.model.subscribe.manager.AppVipManager;
import com.photoeditor.demo.model.subscribe.manager.SVipConstant;
import com.photoeditor.demo.model.subscribe.manager.SVipController;
import com.photoeditor.demo.statistics.StatisticsConstant;
import com.photoeditor.demo.statistics.StatisticsUtils;
import com.photoeditor.demo.ui.activity.edit.EditorImageActivity;
import com.photoeditor.demo.ui.activity.subscribe.SubscribeActivity;
import com.photoeditor.demo.ui.widget.CustomNumSeekBar;
import com.photoeditor.demo.ui.widget.HorizontalListView;
import com.photoeditor.demo.ui.widget.LoadingView;
import com.photoeditor.demo.ui.widget.beauty.BigEyesView;
import com.photoeditor.demo.ui.widget.beauty.BreastView;
import com.photoeditor.demo.ui.widget.beauty.CustomSeekButton;
import com.photoeditor.demo.ui.widget.beauty.FilterAdjuster;
import com.photoeditor.demo.ui.widget.beauty.IBigEyeOperationListener;
import com.photoeditor.demo.ui.widget.beauty.RepairView;
import com.photoeditor.demo.ui.widget.beauty.TailImageView;
import com.photoeditor.demo.ui.widget.image.brush.BrushView;
import com.photoeditor.demo.ui.widget.image.brush.MopiBrushView;
import com.photoeditor.demo.ui.widget.image.brush.WhitenBrushView;
import com.photoeditor.demo.ui.widget.image.enlarge.EnlargerView;
import com.photoeditor.demo.ui.widget.image.hair.Color_view;
import com.photoeditor.demo.ui.widget.image.hair.CustomSizeSeekBar;
import com.photoeditor.demo.ui.widget.image.hair.HairColorConstant;
import com.photoeditor.demo.ui.widget.image.hair.HairColorListAdapter;
import com.photoeditor.demo.ui.widget.image.hair.IStrokenChangeListener;
import com.photoeditor.demo.ui.widget.image.hair.InsideResColorBean;
import com.photoeditor.demo.ui.widget.image.hair.OnSeekBarChangeListener;
import com.photoeditor.demo.ui.widget.image.lip.InsideLipColorModeBean;
import com.photoeditor.demo.ui.widget.image.lip.LipColorConstant;
import com.photoeditor.demo.ui.widget.image.lip.LipView;
import com.photoeditor.demo.util.AsyncTask;
import com.photoeditor.demo.util.CameraDrawable;
import com.photoeditor.demo.util.FontUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static com.photoeditor.demo.statistics.StatisticsConstant.MAIN_BTN_BEAUTY;
import static com.photoeditor.demo.statistics.StatisticsConstant.MAIN_BTN_BODY;
import static com.photoeditor.demo.statistics.StatisticsConstant.UMENG_CUSTOM_EVENT_EDITOR;
import static com.photoeditor.demo.statistics.StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_CLICK;
import static com.photoeditor.demo.statistics.StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_SHOW;
import static com.photoeditor.demo.statistics.StatisticsConstant.UMENG_CUSTOM_KEY_FUNCTION;
import static com.photoeditor.demo.statistics.StatisticsConstant.UMENG_CUSTOM_UNDER_LINE;


public class BeautyBarView extends RelativeLayout implements IDealInit, IEditOpearation, View.OnClickListener {
    private IndicativeHorizontalScrollView mButtonScrollView;
    private LinearLayout mButtonLayout;

    private FrameLayout mOperationPanel;
    private CustomTabButton mOneKeyBt;
    private CustomTabButton mMopiBt;
    /*private CustomTabButton mWhiteningBt;
    private CustomTabButton mComplexionBt;*/
    private CustomTabButton mHairBt;
    private CustomTabButton mEyesBt;
    private CustomTabButton mTailBt;
    private CustomTabButton mLipBt;
    private CustomTabButton mWhitenTeethBt;
    private CustomTabButton mRepairBt;
    private CustomTabButton mBoobJobBt;
    private CustomTabButton mButtocksBt;
    private CustomTabButton mFemaleAbsBt;
    private CustomTabButton mMaleAbsBt;
    private CustomTabButton mPecsBt;
    private CustomTabButton mBicepBt;

    private View mFlOneKey;
    private View mFlMopi;
    /*private View mFlWhitening;
    private View mFlComplexion;*/
    private View mFlHair;
    private View mFlEyes;
    private View mFlTail;
    private View mFlLip;
    private View mFlWhitenTeeth;
    private View mFlRepair;
    private View mFlBoobJob;
    private View mFlButtocks;
    private View mFlFamaleAbs;
    private View mFlMaleAbs;
    private View mFlPecs;
    private View mFlBicep;

    //一键美颜
    private View mOneKeyLayout;
    private CustomSeekButton mOneKeySeekBt;

    //磨皮
    private View mMopiLayout;
    private CustomSizeSeekBar mMopiSeekbar;
    private ImageView mMopiSwitchPaint;
    private ImageView mMopiSwitchEarse;

    //美白
    private View mWhiteningLayout;
    private CustomSizeSeekBar mWhiteningSeekbar;
    private ImageView mWhitenSwitchPaint;
    private ImageView mWhitenSwitchEarse;

    //肤色
    private View mComplexionLayout;
    private TextView mComplexionText1;
    private TextView mComplexionText2;
    private CustomNumSeekBar mComplexionSeekbar;

    //发色
    private View mHairLayout;
    private CustomSizeSeekBar mHairStrokenSeekbar;
    private ImageView mHairSwitchPaint;
    private ImageView mHairSwitchEarse;
    /*private CheckableImageView mSwitchPaint;
    private CheckableImageView mSwitchEarse;*/
    private HorizontalListView mHairColorList;
    private HairColorListAdapter mHairColorAdapter;

    private View mLipLayout;
    private CustomSizeSeekBar mLipStrokenSeekbar;
    /*private CheckableImageView mLipSwitchPaint;
    private CheckableImageView mLipSwitchEarse;*/
    private ImageView mLipSwitchPaint;
    private ImageView mLipSwitchEarse;
    private HorizontalListView mLipColorList;
    private HairColorListAdapter mLipColorAdapter;


    //美白牙齿
    private View mWhitenTeethLayout;
    private CustomSizeSeekBar mWhitenTeethStrokenSeekbar;
    private ImageView mWhitenTeethSwitchPaint;
    private ImageView mWhitenTeethSwitchEarse;

    //大眼
    private View mEyesLayout;
    private TextView mEyesText1;
    private TextView mEyesText2;
    private CustomNumSeekBar mEyesSeekbar;

    //增高
    private View mTailLayout;
    private CustomNumSeekBar mTailSeekbar;

    //修复
    private View mRepairLayout;
    private CustomSizeSeekBar mRepairSeekBar;

    //丰胸
    private View mBoobJobLayout;
    private CustomNumSeekBar mBoobJobSeekbar;

    //美臀
    private View mButtocksLayout;
    private CustomNumSeekBar mButtocksSeekbar;

    private int mCurId = -1;

    //undo 和 查看原图的
    private View mUndo;
    private View mRedo;
    private View mSwitch;

    private Color_view mHairColorView;
    private BigEyesView mBigEyesView;
    private TailImageView mTailView;
    private LipView mLipView;
    private RepairView mRepairView;
    private BrushView mWhitenTeethView;
    private MopiBrushView mMopiBrushView;
    private WhitenBrushView mWhitenBrushView;
    private BreastView mBreastView;
    private BreastView mButtocksView;

    private List<View> mVipViews;

    //美颜调节滤镜
    private GPUImageWhiteBalanceAndToneCurveFilter mOneKeyFilter;

    //toneCurve
    private GPUImageWhiteBalanceFilter mComplexionFilter;
    private FilterAdjuster mComplexionAdjuster;

    //whitening
    private GPUImageToneCurveFilter mWhitenFilter;
    private FilterAdjuster mWhitenAdjuster;

    //丰胸
    private TwinEnLargerFilter mBoobJobFilter;
    private FilterAdjuster mBoobJobAdjuster;

    //美臀
    private EnLargerFilter mButtocksFilter;
    private FilterAdjuster mButtocksAdjuster;

    private GPUImageFilter mDefaultFilter;
    //滤镜调整器
    private FilterAdjuster mOneKeyAdjuster;

    private AdjustGPUImageView mAdjustGPUImageView;
    private ImageView mImageViewCover;
    private LoadingView mAnimatorView;

    private final int START_ANIMATION = 1001;
    private final int STOP_ANIMATION = 1002;
    private final int ONE_KEY_BEAUTY = 1003;
    private final int MOPI = 1004;

    private boolean mIsDealOver = false;

    private boolean mBitmapDealOver = false;
    private boolean mStartAnimation = false;
    private boolean mStopAnimation = false;

    private EditorImageActivity mActivity;

    private Bitmap mSrcBitmap;//进入时的Bitmap

    private Bitmap mCacheBitmap;

    private AsyncTask mTask;

    private boolean mIsNeedSave;//用于标识是否可以保存

    private boolean mDoLightAnim = true;

    private boolean mBoobJobBtnShowing;
    private boolean mButtocksBtnShowing;

    /**
     * 根据不同的类型显示不同的功能
     */
    private int mStateType = TYPE_BEAUTY;
    public static final int TYPE_BEAUTY = 1;
    public static final int TYPE_BODY = 2;
    public static final int TYPE_NONE = -1;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == STOP_ANIMATION) {
                if (mAnimatorView != null) {
                    mAnimatorView.stopLoading();
                }
                if (mDoLightAnim && mCurId != R.id.mopi_beauty_button) {
                    mDoLightAnim = false;
                    doLightAnim();
                    return;
                }
                if (mCacheBitmap != null && !mCacheBitmap.isRecycled()) {
                    mAdjustGPUImageView.getGPUImage().deleteImage();
                    mAdjustGPUImageView.setImage(mCacheBitmap);
                }
                if (mCurId != R.id.mopi_beauty_button) {
                    mIsDealOver = true;
                    mActivity.setConfirmEnable(true);
                }
            } else if (msg.what == START_ANIMATION) {
                mAnimatorView.startLoading();
                mStartAnimation = true;
                if (!mStopAnimation && mBitmapDealOver) {
                    mStopAnimation = true;
                    mHandler.sendEmptyMessageDelayed(STOP_ANIMATION, 700);
                }
            } else if (msg.what == ONE_KEY_BEAUTY) {
                doMopi(true);
            } else if (msg.what == MOPI) {
                doMopi(false);
            }
        }
    };
    private View mReset;
    private boolean mRetouchUsed;
    private boolean mHealingUsed;
    private boolean mWhitenUsed;
    private boolean mSmoothUsed;
    private boolean mGlowUsed;
    private boolean mHairColorUsed;
    private boolean mLipstickUsed;
    private boolean mBoobjobUsed;
    private boolean mButtocksUsed;
    private boolean mBlushUsed;
    private boolean mEyeTuneUsed;
    private boolean mTallerUsed;
    private boolean mEyeShadowUsed;
    private boolean mEyeLashUsed;
    private boolean mContanctLenseUsed;
    private boolean mBicepUsed;
    private boolean mMaleAbsUsed;
    private boolean mPecsUsed;
    private boolean mFemaleAbsUsed;

    private float mHorizontalItemWidth = -1;
    private int mBarItemCount = -1;
    private float mFraction;
    private float mHorizontalBarScrollX;

    private boolean mCheck2Save;

    private View floatingWindow;

    public BeautyBarView(Context context) {
        this(context, null);
    }

    public BeautyBarView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BeautyBarView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mActivity = (EditorImageActivity) context;
        mOneKeyFilter = new GPUImageWhiteBalanceAndToneCurveFilter();
        mOneKeyAdjuster = new FilterAdjuster(mOneKeyFilter);
        mComplexionFilter = new GPUImageWhiteBalanceFilter();
        mComplexionAdjuster = new FilterAdjuster(mComplexionFilter);
        mWhitenFilter = new GPUImageToneCurveFilter();
        mWhitenAdjuster = new FilterAdjuster(mWhitenFilter);
        mBoobJobFilter = new TwinEnLargerFilter(
                EnlargerView.SCALE, EnlargerView.RADIU, new PointF(EnlargerView.CENTER_X_FIRST, EnlargerView.CENTER_Y),
                EnlargerView.SCALE, EnlargerView.RADIU, new PointF(EnlargerView.CENTER_X_SECOND, EnlargerView.CENTER_Y));
        mBoobJobAdjuster = new FilterAdjuster(mBoobJobFilter);
        mButtocksFilter = new EnLargerFilter(EnlargerView.SCALE, EnlargerView.RADIU, new PointF(EnlargerView.CENTER_X, EnlargerView.CENTER_Y));
        mButtocksAdjuster = new FilterAdjuster(mButtocksFilter);
        mDefaultFilter = new GPUImageFilter();
        mIsNeedSave = false;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mButtonScrollView = (IndicativeHorizontalScrollView) findViewById(R.id.button_scrollView);
        mButtonLayout = (LinearLayout) findViewById(R.id.button_layout);
        mOneKeyBt = (CustomTabButton) findViewById(R.id.onekey_beauty_button);
        mMopiBt = (CustomTabButton) findViewById(R.id.mopi_beauty_button);
//        mWhiteningBt = (CustomTabButton) findViewById(R.id.whitening_beauty_button);
//        mComplexionBt = (CustomTabButton) findViewById(R.id.complexion_beauty_button);
        mHairBt = (CustomTabButton) findViewById(R.id.hair_beauty_button);
        mEyesBt = (CustomTabButton) findViewById(R.id.eyes_beauty_button);
        mTailBt = (CustomTabButton) findViewById(R.id.tail_beauty_button);
        mLipBt = (CustomTabButton) findViewById(R.id.lip_beauty_button);
        mRepairBt = (CustomTabButton) findViewById(R.id.repair_button);
        mWhitenTeethBt = (CustomTabButton) findViewById(R.id.whiten_teeth_button);
        mFemaleAbsBt = (CustomTabButton) findViewById(R.id.female_abs_button);
        mMaleAbsBt = (CustomTabButton) findViewById(R.id.male_abs_button);
        mPecsBt = (CustomTabButton) findViewById(R.id.pecs_button);
        mBicepBt = (CustomTabButton) findViewById(R.id.bicep_button);
        mBoobJobBt = findViewById(R.id.boobjob_beauty_button);
        mButtocksBt = findViewById(R.id.buttocks_beauty_button);

        mFlOneKey = findViewById(R.id.fl_onekey_beauty);
        mFlMopi = findViewById(R.id.fl_mopi_beauty);
//        mFlWhitening = findViewById(R.id.fl_whitening_beauty);
//        mFlComplexion = findViewById(R.id.fl_complexion_beauty);
        mFlHair = findViewById(R.id.fl_hair_beauty);
        mFlEyes = findViewById(R.id.fl_eyes_beauty);
        mFlTail = findViewById(R.id.fl_tail_beauty);
        mFlLip = findViewById(R.id.fl_lip_beauty);
        mFlRepair = findViewById(R.id.fl_repair);
        mFlFamaleAbs = findViewById(R.id.fl_female_abs);
        mFlMaleAbs = findViewById(R.id.fl_male_abs);
        mFlPecs = findViewById(R.id.fl_pecs);
        mFlBicep = findViewById(R.id.fl_bicep);
        mFlWhitenTeeth = findViewById(R.id.fl_whiten_teeth);
        mFlBoobJob = findViewById(R.id.fl_boobjob_beauty);
        mFlButtocks = findViewById(R.id.fl_buttocks_beauty);

        mOperationPanel = (FrameLayout) findViewById(R.id.operation_pannel);

        mVipViews = new ArrayList<View>();
        mVipViews.add(findViewById(R.id.iv_vip_retouch));
        mVipViews.add(findViewById(R.id.iv_vip_smooth));
        mVipViews.add(findViewById(R.id.iv_vip_whiten));
        mVipViews.add(findViewById(R.id.iv_vip_healing));

        updateVipStatus();

        mRedo = findViewById(R.id.muscle_redo);
        mUndo = findViewById(R.id.color_hair_undo);
        mReset = findViewById(R.id.tail_reset);
        mSwitch = findViewById(R.id.color_hair_switch);
        mRedo.setOnClickListener(this);
        mUndo.setOnClickListener(this);
        mReset.setOnClickListener(this);
        mSwitch.setOnClickListener(this);
        mSwitch.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if (mCurId == R.id.hair_beauty_button) {
                        mHairColorView.showOriginalBitmap();
                    } else if (mCurId == R.id.eyes_beauty_button) {
                        mBigEyesView.showOriginalBitmap();
                    } else if (mCurId == R.id.lip_beauty_button) {
                        mLipView.showOriginalBitmap();
                    } else if (mCurId == R.id.whiten_teeth_button) {
                        mWhitenTeethView.showOriginalBitmap();
                    } else if (mCurId == R.id.tail_beauty_button) {
                        mTailView.showOriginalBitmap();
                    } else if (mCurId == R.id.mopi_beauty_button) {
                        mMopiBrushView.showOriginalBitmap();
                    } else if (mCurId == R.id.whitening_beauty_button) {
                        mWhitenBrushView.showOriginalBitmap();
                    } else if (mCurId == R.id.repair_button) {
                        mRepairView.showOriginalBitmap();
                    } else if (mCurId == R.id.boobjob_beauty_button) {
                        mBreastView.showOriginalBitmap();
                    } else if (mCurId == R.id.buttocks_beauty_button) {
                        mButtocksView.showOriginalBitmap();
                    }

//                    mSwitch.setImageResource(R.drawable.image_edit_hair_switch_click);
                } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
                    if (mCurId == R.id.hair_beauty_button) {
                        mHairColorView.showEffect();
                    } else if (mCurId == R.id.eyes_beauty_button) {
                        mBigEyesView.showEffect();
                    } else if (mCurId == R.id.lip_beauty_button) {
                        mLipView.showEffect();
                    } else if (mCurId == R.id.whiten_teeth_button) {
                        mWhitenTeethView.showEffect();
                    } else if (mCurId == R.id.tail_beauty_button) {
                        mTailView.showEffect();
                    } else if (mCurId == R.id.mopi_beauty_button) {
                        mMopiBrushView.showEffect();
                    } else if (mCurId == R.id.whitening_beauty_button) {
                        mWhitenBrushView.showEffect();
                    } else if (mCurId == R.id.repair_button) {
                        mRepairView.showEffect();
                    } else if (mCurId == R.id.boobjob_beauty_button) {
                        mBreastView.showEffect();
                    } else if (mCurId == R.id.buttocks_beauty_button) {
                        mButtocksView.showEffect();
                    }
//                    mSwitch.setImageResource(R.drawable.image_edit_hair_switch);
                }
                return false;
            }
        });

        int width = (int) (ImageHelper.SCREEN_WIDTH / 5.58f);
        int count = mButtonLayout.getChildCount();
        for (int i = 0; i < count; i++) {
            View v = mButtonLayout.getChildAt(i);
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) v.getLayoutParams();
            lp.width = width;
            v.setLayoutParams(lp);
        }

        ((IndicativeHorizontalScrollView) findViewById(R.id.button_scrollView)).setOnScrollXListener(new IndicativeHorizontalScrollView.OnScrollXListener() {
            @Override
            public void onScrollX(int scrollX, boolean toLeft) {
                if (toLeft) {
                    int scrollCount = scrollX / MENU_SIZE + 1;
                    if (mLastScrollCountFirst != scrollCount && scrollCount <= mMenuSizeOutOfScreenFirst) {
                        mLastScrollCountFirst = scrollCount;
                        int cur = mMenuSizeOfScreen + scrollCount - 1;
                        if (cur == 7) {
                            StatisticsUtils.statisicsCustomFunction(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_PREVIEW_VALUE_BOOBJOB_SHOW);
                        } else if (cur == 8) {
                            StatisticsUtils.statisicsCustomFunction(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_PREVIEW_VALUE_BUTTOCKS_SHOW);
                        }
                    }
                } else {
                    int scrollCount = scrollX / MENU_SIZE;
                    if (mLastScrollCountFirst != scrollCount) {
                        mLastScrollCountFirst = scrollCount;
                        if (mLastScrollCountFirst == 7) {
                            StatisticsUtils.statisicsCustomFunction(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_PREVIEW_VALUE_BOOBJOB_SHOW);
                        } else if (mLastScrollCountFirst == 8) {
                            StatisticsUtils.statisicsCustomFunction(StatisticsConstant.UMENG_CUSTOM_EVENT_FUNC_PREVIEW_VALUE_BUTTOCKS_SHOW);
                        }
                    }
                }
            }
        });
        mMenuSizeOfScreen = ImageHelper.SCREEN_WIDTH / MENU_SIZE + 1;
        mMenuSizeOutOfScreenFirst = first_menu_count - mMenuSizeOfScreen;

        chageStateType(mStateType);
    }

    private static final int MENU_SIZE = DeviceUtils.dip2px(62);
    private static final int first_menu_count = 12;
    private int mMenuSizeOfScreen;//屏幕内的数量
    private int mMenuSizeOutOfScreenFirst;//屏幕外的数量
    private int mLastScrollCountFirst = 0;

    public void updateVipStatus() {
        if (mVipViews != null) {
            int visibility = AppVipManager.isAdVip() ? GONE : VISIBLE;
            for (View view : mVipViews) {
                view.setVisibility(visibility);
            }
        }
    }

    @Override
    public void onClick(View v) {
        if (mSrcBitmap == null) {
            return;
        }
        if (isVipButton(v)){
            showFloatingWindow();
            return;
        }
        deleteFloatingWindow();
        int id = v.getId();
        if (id == R.id.onekey_beauty_button) {
            initOneKeyBeautyLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.onekey_beauty_button);
        } else if (id == R.id.mopi_beauty_button) {
            if (!SPDataManager.hasUseSmooth()) {
                SPDataManager.setHasUseSmooth(true);
            }
            initMopiLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.mopi_beauty_button);
        } else if (id == R.id.repair_button) {
            if (!SPDataManager.hasUseHealing()) {
                SPDataManager.setHasUseHealing(true);
            }
            initRepairLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.repair_button);
        } else if (id == R.id.whitening_beauty_button) {
            if (!SPDataManager.hasUseGlow()) {
                SPDataManager.setHasUseGlow(true);
            }
            initWhiteningLayout();
            selectTab(id);
            enterTab(id);
        } else if (id == R.id.complexion_beauty_button) {
            initComplexionLayout();
            selectTab(id);
            enterTab(id);
        } else if (id == R.id.hair_beauty_button) {
            if (!SPDataManager.hasUseHairColor()) {
                SPDataManager.setHasUseHairColor(true);
            }
            initHairLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.hair_beauty_button);
        } else if (id == R.id.lip_beauty_button) {
            if (!SPDataManager.hasUseLipstick()) {
                SPDataManager.setHasUseLipstick(true);
            }
            initLipLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.lip_beauty_button);
        } else if (id == R.id.eyes_beauty_button) {
            if (!SPDataManager.hasUseEyeTuner()) {
                SPDataManager.setHasUseEyeTuner(true);
            }
            initEyesLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.eyes_beauty_button);
        } else if (id == R.id.tail_beauty_button) {
            if (!SPDataManager.hasUseTaller()) {
                SPDataManager.setHasUseTaller(true);
            }
            initTailLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.tail_beauty_button);
        } else if (id == R.id.whiten_teeth_button) {
            if (!SPDataManager.hasUseWhiten()) {
                SPDataManager.setHasUseWhiten(true);
            }
            initWhitenTeethLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.whiten_teeth_button);
        } else if (id == R.id.switch_paint) {
            //mSwitchEarse.setChecked(false);
            mHairSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mHairSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mHairColorView.switchToDraw();
        } else if (id == R.id.switch_earse) {
            //mSwitchPaint.setChecked(false);
            mHairSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint);
            mHairSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser_light);
            mHairColorView.switchToErase();
        } else if (id == R.id.lip_switch_paint) {
            mLipSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mLipSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mLipView.switchToDraw();
        } else if (id == R.id.lip_switch_earse) {
            mLipSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint);
            mLipSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser_light);
            mLipView.switchToErase();
        } else if (id == R.id.whiten_teeth_switch_paint) {
            mWhitenTeethSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mWhitenTeethSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mWhitenTeethView.switchToDraw();
        } else if (id == R.id.whiten_teeth_switch_earse) {
            mWhitenTeethSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint);
            mWhitenTeethSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser_light);
            mWhitenTeethView.switchToErase();
        } else if (id == R.id.mopi_switch_paint) {
            mMopiSwitchPaint.setSelected(true);
            mMopiSwitchEarse.setSelected(false);
            mMopiSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mMopiSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mMopiBrushView.switchToDraw();
        } else if (id == R.id.mopi_switch_earse) {
            mMopiSwitchPaint.setSelected(false);
            mMopiSwitchEarse.setSelected(true);
            mMopiSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint);
            mMopiSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser_light);
            mMopiBrushView.switchToErase();
        } else if (id == R.id.whiten_switch_paint) {
            mWhitenSwitchPaint.setSelected(true);
            mWhitenSwitchEarse.setSelected(false);
            mWhitenSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mWhitenSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mWhitenBrushView.switchToDraw();
        } else if (id == R.id.whiten_switch_earse) {
            mWhitenSwitchPaint.setSelected(false);
            mWhitenSwitchEarse.setSelected(true);
            mWhitenSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint);
            mWhitenSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser_light);
            mWhitenBrushView.switchToErase();
        } else if (id == R.id.color_hair_undo) {
            if (mCurId == R.id.hair_beauty_button) {
                mHairColorView.undo();
            } else if (mCurId == R.id.eyes_beauty_button) {
                mBigEyesView.undo();
            } else if (mCurId == R.id.lip_beauty_button) {
                mLipView.undo();
            } else if (mCurId == R.id.whiten_teeth_button) {
                mWhitenTeethView.undo();
            } else if (mCurId == R.id.mopi_beauty_button) {
                mMopiBrushView.undo();
            } else if (mCurId == R.id.whitening_beauty_button) {
                mWhitenBrushView.undo();
            } else if (mCurId == R.id.repair_button) {
                mRepairView.undo();
            }
        } else if (id == R.id.tail_reset) {
            mTailView.reset();
            mReset.setVisibility(View.GONE);
            mSwitch.setVisibility(View.GONE);
        } else if (id == R.id.boobjob_beauty_button) {
            if (!SPDataManager.hasUseBoobJob()) {
                SPDataManager.setHasUseBoobJob(true);
            }
            initBoobJobLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.boobjob_beauty_button);
        } else if (id == R.id.buttocks_beauty_button) {
            if (!SPDataManager.hasUseButtocks()) {
                SPDataManager.setHasUseButtocks(true);
            }
            initButtocksLayout();
            selectTab(id);
            enterTab(id);
            statisticBeautyBarClick(R.id.buttocks_beauty_button);
        }
    }



    private boolean isVipButton(View v) {
        boolean isVip = false;
        if (v.getId() == R.id.onekey_beauty_button){
            if (mVipViews.get(0).getVisibility() == View.VISIBLE){
                isVip = true;
            }
        }else if (v.getId() == R.id.repair_button){
            if (mVipViews.get(1).getVisibility() == View.VISIBLE){
                isVip = true;
            }
        }else if (v.getId() == R.id.mopi_beauty_button){
            if (mVipViews.get(2).getVisibility() == View.VISIBLE){
                isVip = true;
            }
        }else if (v.getId() == R.id.whiten_teeth_button) {
            if (mVipViews.get(3).getVisibility() == View.VISIBLE) {
                isVip = true;
            }
        }

        return isVip;
    }

    public void showFloatingWindow() {
        if (floatingWindow == null) {
            Activity activity = (Activity) getContext();
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            lp.topMargin = mButtonScrollView.getTop()-mButtonScrollView.getHeight()-8;
            floatingWindow = View.inflate(activity, R.layout.floating_window, null);
            FrameLayout contentView =  (FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content);
            ViewGroup viewGroup =  (ViewGroup)contentView.getChildAt(0);
            viewGroup.addView(floatingWindow, lp);

            StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_FLOAT_SHOW,
                    StatisticsConstant.KEY_VIP_FUN, StatisticsConstant.VALUE_VIP_FUN_TOOL);

            floatingWindow.findViewById(R.id.iv).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    SVipController.showSubscribeActivity(mActivity, SVipConstant.VIP_ENTRANCE_EDIT, StatisticsConstant.ENTRANCE_VALUE_BEAUTY);
                    //activity.startActivity(new Intent(activity, SubscribeActivity.class));
                    StatisticsUtils.statisticGrowingIo(StatisticsConstant.EVENT_FLOAT_BUTT_CLICK,
                            StatisticsConstant.KEY_VIP_FUN, StatisticsConstant.VALUE_VIP_FUN_TOOL);
                }
            });
        }
    }

    public void deleteFloatingWindow() {
        if (floatingWindow != null) {
            Activity activity = (Activity) getContext();
            FrameLayout contentView =  (FrameLayout) activity.getWindow().getDecorView().findViewById(android.R.id.content);
            ViewGroup viewGroup =  (ViewGroup)contentView.getChildAt(0);
            viewGroup.removeView(floatingWindow);
            floatingWindow = null;
        }
    }

    private void statisticBeautyBarClick(int id) {
        switch (id) {
            case R.id.onekey_beauty_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "retouch" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("retouch");
                break;
            case R.id.mopi_beauty_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "smooth" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("smooth");
                break;
            case R.id.hair_beauty_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "hairdye" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("hairdye");
                break;
            case R.id.repair_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "healing" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("healing");
                break;
            case R.id.whiten_teeth_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "whiten" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("whiten");
                break;
            case R.id.eyes_beauty_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "eye tune" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("eye tune");
                break;
            case R.id.lip_beauty_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "lip stick" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("lip stick");
                break;
            case R.id.male_abs_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "male abs" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("male abs");
                break;
            case R.id.pecs_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "pecs" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("pecs");
                break;
            case R.id.bicep_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "bicep" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("bicep");
                break;
            case R.id.female_abs_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "female abs" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("female abs");
                break;
            case R.id.boobjob_beauty_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "boob job" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("boob job");
                break;
            case R.id.buttocks_beauty_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "buttocks" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("buttocks");
                break;
            case R.id.tail_beauty_button:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "taller" + UMENG_CUSTOM_EVENT_FUNC_CLICK);
                SPDataManager.setSaveFunctionName("taller");
                break;
            default:
        }
    }

    /**
     * 选中然后隐藏所有的operation pannel
     * 显示对应的contentView
     *
     * @param id
     */
    private void selectTab(int id) {
        mCurId = id;
        int childCount = mOperationPanel.getChildCount();
        for (int i = 0; i < childCount; i++) {
            mOperationPanel.getChildAt(i).setVisibility(GONE);
        }
        if (mCurId == R.id.onekey_beauty_button) {
            mAdjustGPUImageView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mOneKeyLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.whitening_beauty_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mButtonScrollView.setVisibility(GONE);
            mWhiteningLayout.setVisibility(VISIBLE);
            mWhitenBrushView.setVisibility(VISIBLE);
        } else if (mCurId == R.id.complexion_beauty_button) {
            mAdjustGPUImageView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mComplexionLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.mopi_beauty_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mMopiBrushView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mMopiLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.hair_beauty_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mHairColorView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mHairLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.lip_beauty_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mLipView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mLipLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.eyes_beauty_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mBigEyesView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mEyesLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.tail_beauty_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mTailView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mTailLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.repair_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mRepairView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mRepairLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.whiten_teeth_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mWhitenTeethView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mWhitenTeethLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.boobjob_beauty_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mBreastView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mBoobJobLayout.setVisibility(VISIBLE);
        } else if (mCurId == R.id.buttocks_beauty_button) {
            mAdjustGPUImageView.setVisibility(GONE);
            mButtocksView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(GONE);
            mButtocksLayout.setVisibility(VISIBLE);
        } else {
            mHairColorView.setVisibility(GONE);
            mLipView.setVisibility(GONE);
            mBigEyesView.setVisibility(GONE);
            mTailView.setVisibility(GONE);
            mRepairView.setVisibility(GONE);
            mWhitenTeethView.setVisibility(GONE);
            mWhitenBrushView.setVisibility(GONE);
            mMopiBrushView.setVisibility(GONE);
            mBreastView.setVisibility(GONE);
            mButtocksView.setVisibility(GONE);
            mAdjustGPUImageView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(VISIBLE);
        }
    }

    private void enterTab(int id) {
        if (id == R.id.onekey_beauty_button) {
            mIsDealOver = false;
            mBitmapDealOver = false;
            mImageViewCover.setImageBitmap(getSrcBitmap());
            setSrcBitmap(getSrcBitmap());
            mAdjustGPUImageView.setFilter(mOneKeyFilter);
            mHandler.sendEmptyMessageDelayed(START_ANIMATION, 200);//启动动画
            mHandler.sendEmptyMessageDelayed(ONE_KEY_BEAUTY, 400);//进行磨皮
            mActivity.setConfirmEnable(false);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_onekey_beauty, View.NO_ID);
        } else if (id == R.id.whitening_beauty_button) {
            if (mWhitenBrushView.isChanged()) {
                mUndo.setVisibility(VISIBLE);
                mSwitch.setVisibility(VISIBLE);
            } else {
                mUndo.setVisibility(GONE);
                mSwitch.setVisibility(GONE);
            }
            mWhitenBrushView.create(mSrcBitmap);
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_brighten, R.drawable.ic_tool_help);
        } else if (id == R.id.complexion_beauty_button) {
            mImageViewCover.setImageBitmap(getSrcBitmap());
            mComplexionSeekbar.setDefaultColorStyle();
            setSrcBitmap(getSrcBitmap());
            mAdjustGPUImageView.setFilter(mComplexionFilter);
            dealComplexion(mComplexionSeekbar.getProgress());
            mAdjustGPUImageView.requestRender();
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_complexion, View.NO_ID);
        } else if (id == R.id.mopi_beauty_button) {
            mIsDealOver = false;
            mBitmapDealOver = false;
            mHandler.sendEmptyMessageDelayed(START_ANIMATION, 50);//启动动画
            mHandler.sendEmptyMessageDelayed(MOPI, 10);//进行磨皮
            if (mMopiBrushView.isChanged()) {
                mUndo.setVisibility(VISIBLE);
                mSwitch.setVisibility(VISIBLE);
            } else {
                mUndo.setVisibility(GONE);
                mSwitch.setVisibility(GONE);
            }
            mMopiBrushView.create(mSrcBitmap);
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_mopi, R.drawable.ic_tool_help);
        } else if (id == R.id.hair_beauty_button) {
            if (mHairColorView.isChanged()) {
                mUndo.setVisibility(VISIBLE);
                mSwitch.setVisibility(VISIBLE);
            } else {
                mUndo.setVisibility(GONE);
                mSwitch.setVisibility(GONE);
            }
            BgBean bgBean = mHairColorAdapter.getItem(0);
            if (bgBean instanceof InsideResColorBean) {
                InsideResColorBean colorBgBean = (InsideResColorBean) bgBean;
                int color = colorBgBean.getColor();
                mHairColorView.create(mSrcBitmap, color);
            }
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_hair, R.drawable.ic_tool_help);
            //引导
            if (SPDataManager.getEditShowHairColorTip()) {
                RelativeLayout guideView = mActivity.showGuideView();
                View tipLayout = mActivity.getLayoutInflater().inflate(R.layout.image_edit_beauty_hair_color_tip, null);
                LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
                guideView.addView(tipLayout, lp);
            }
        } else if (id == R.id.lip_beauty_button) {
            if (mLipView.isChanged()) {
                mUndo.setVisibility(VISIBLE);
                mSwitch.setVisibility(VISIBLE);
            } else {
                mUndo.setVisibility(GONE);
                mSwitch.setVisibility(GONE);
            }
            BgBean bgBean = mLipColorAdapter.getItem(0);
            if (bgBean instanceof InsideLipColorModeBean) {
                InsideLipColorModeBean colorBgBean = (InsideLipColorModeBean) bgBean;
                mLipView.create(mSrcBitmap, colorBgBean.getColor(), colorBgBean.getOverlyingMode());
            }
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_lip, R.drawable.ic_tool_help);
            //引导
            if (SPDataManager.getEditShowHairColorTip()) {
                RelativeLayout guideView = mActivity.showGuideView();
                View tipLayout = mActivity.getLayoutInflater().inflate(R.layout.image_edit_beauty_hair_color_tip, null);
                LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                lp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
                guideView.addView(tipLayout, lp);
            }
        } else if (id == R.id.eyes_beauty_button) {
            if (mBigEyesView.isChanged()) {
                mUndo.setVisibility(VISIBLE);
                mSwitch.setVisibility(VISIBLE);
            } else {
                mUndo.setVisibility(GONE);
                mSwitch.setVisibility(GONE);
            }
            mEyesSeekbar.setDefaultColorStyle();
            mBigEyesView.setOriginalBitmap(mSrcBitmap);
            mBigEyesView.setImageBitmap(mSrcBitmap, true);
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_big_eyes, R.drawable.ic_tool_help);
        } else if (id == R.id.tail_beauty_button) {
            if (mTailView.isChanged()) {
                mReset.setVisibility(VISIBLE);
                mSwitch.setVisibility(VISIBLE);
            } else {
                mReset.setVisibility(GONE);
                mSwitch.setVisibility(GONE);
            }
            mTailSeekbar.setDefaultColorStyle();
            mTailView.setImageBitmap(mSrcBitmap, true);
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_tail, R.drawable.ic_tool_help);
        } else if (id == R.id.whiten_teeth_button) {
            if (mWhitenTeethView.isChanged()) {
                mUndo.setVisibility(VISIBLE);
                mSwitch.setVisibility(VISIBLE);
            } else {
                mUndo.setVisibility(GONE);
                mSwitch.setVisibility(GONE);
            }
            mWhitenTeethView.create(mSrcBitmap);
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_whiten_teeth, R.drawable.ic_tool_help);
        } else if (id == R.id.repair_button) {
            if (mRepairView.isChanged()) {
                mUndo.setVisibility(VISIBLE);
                mSwitch.setVisibility(VISIBLE);
            } else {
                mUndo.setVisibility(GONE);
                mSwitch.setVisibility(GONE);
            }
            mRepairView.setOriginalBitmap(mSrcBitmap);
            mRepairView.setImageBitmap(mSrcBitmap, true);
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_repair, R.drawable.ic_tool_help);
        } else if (id == R.id.boobjob_beauty_button) {
            mSwitch.setVisibility(GONE);
            mUndo.setVisibility(GONE);
            mBreastView.setOriginalBitmap(mSrcBitmap);
            mBreastView.setImageBitmap(mSrcBitmap, true);
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_boobjob, R.drawable.ic_tool_help);
        } else if (id == R.id.buttocks_beauty_button) {
            mSwitch.setVisibility(GONE);
            mUndo.setVisibility(GONE);
            mButtocksView.setOriginalBitmap(mSrcBitmap);
            mButtocksView.setImageBitmap(mSrcBitmap, true);
            mActivity.setConfirmEnable(true);
            mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_buttocks, R.drawable.ic_tool_help);
        } else {
            mAdjustGPUImageView.getGPUImage().deleteImage();
            mAdjustGPUImageView.setImage(getSrcBitmap());
        }
        if (id == R.id.tail_beauty_button) {
            mActivity.hideTopForTaller();
        } else {
            mActivity.hideTopView();
        }

        mActivity.doShowOperationBarAnim();
    }

    /**
     * 重置某个Tab或者整体
     *
     * @param id
     */
    private void reset(int id) {
        if (id == R.id.onekey_beauty_button) {
            if (mTask != null && !mTask.isCancelled()) {
                mTask.cancel(true);
            }
            mHandler.removeMessages(START_ANIMATION);
            mHandler.removeMessages(ONE_KEY_BEAUTY);
            mHandler.removeMessages(STOP_ANIMATION);
            if (mAnimatorView != null) {
                mAnimatorView.stopLoading();
            }
            if (mLightAnimSet != null && mLightAnimSet.isRunning()) {
                mLightAnimSet.cancel();
            }
            mAdjustGPUImageView.setFilter(mDefaultFilter);
            setSrcBitmap(getSrcBitmap());
            mCacheBitmap = null;
            mIsDealOver = false;
            mBitmapDealOver = false;
            mStartAnimation = false;
            mStopAnimation = false;
        } else if (id == R.id.whitening_beauty_button) {
            mWhiteningSeekbar.setProgress(50);//默认值
            mWhitenBrushView.reset();
            mWhitenSwitchPaint.setSelected(true);
            mWhitenSwitchEarse.setSelected(false);
            mWhitenSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mWhitenSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else if (id == R.id.complexion_beauty_button) {
            mAdjustGPUImageView.setFilter(mDefaultFilter);
            setSrcBitmap(getSrcBitmap());
        } else if (id == R.id.mopi_beauty_button) {
            if (mTask != null && !mTask.isCancelled()) {
                mTask.cancel(true);
            }
            mHandler.removeMessages(START_ANIMATION);
            mHandler.removeMessages(MOPI);
            mHandler.removeMessages(STOP_ANIMATION);
            if (mAnimatorView != null) {
                mAnimatorView.stopLoading();
            }
            mCacheBitmap = null;
            mIsDealOver = false;
            mBitmapDealOver = false;
            mStartAnimation = false;
            mStopAnimation = false;
            mMopiSeekbar.setProgress(50);//默认值
            mMopiBrushView.reset();
            mMopiSwitchPaint.setSelected(true);
            mMopiSwitchEarse.setSelected(false);
            mMopiSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mMopiSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else if (id == R.id.hair_beauty_button) {
            mHairStrokenSeekbar.setProgress(50);//默认值
            mHairColorAdapter.setSelectedPosition(0);
            mHairColorView.reset();
            /*mSwitchEarse.setChecked(false);
            mSwitchPaint.setChecked(true);*/
            mHairSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mHairSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else if (id == R.id.lip_beauty_button) {
            mLipStrokenSeekbar.setProgress(50);//默认值
            mLipColorAdapter.setSelectedPosition(0);
            mLipView.reset();
            mLipSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mLipSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else if (id == R.id.eyes_beauty_button) {
            mBigEyesView.reset();
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else if (id == R.id.tail_beauty_button) {
            mTailView.reset();
            mReset.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else if (id == R.id.whiten_teeth_button) {
            mWhitenTeethStrokenSeekbar.setProgress(50);//默认值
            mWhitenTeethView.reset();
            mWhitenTeethSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mWhitenTeethSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else if (id == R.id.repair_button) {
            mRepairView.reset();
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else if (id == R.id.boobjob_beauty_button) {
            mBreastView.reset();
            mBoobJobSeekbar.setProgress(0);
            mReset.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else if (id == R.id.buttocks_beauty_button) {
            mButtocksView.reset();
            mButtocksSeekbar.setProgress(50);
            mReset.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
        } else {//重置界面 保存状态不变
            mCurId = -1;
            selectTab(-1);
            enterTab(-1);
        }

        if (mActivity.isNeedGoToBeauty()) {
            mActivity.showTopView();
            mActivity.doHideOperationBarAnim();
        }
    }

    private void resetTotal() {
        mCurId = -1;
        mHairColorView.setVisibility(GONE);
        mLipView.setVisibility(GONE);
        mBigEyesView.setVisibility(GONE);
        mTailView.setVisibility(GONE);
        mRepairView.setVisibility(GONE);
        mWhitenTeethView.setVisibility(GONE);
        mWhitenBrushView.setVisibility(GONE);
        mMopiBrushView.setVisibility(GONE);
        mBreastView.setVisibility(GONE);
        mButtocksView.setVisibility(GONE);
        mAdjustGPUImageView.setVisibility(VISIBLE);
        mButtonScrollView.setVisibility(VISIBLE);
        mAdjustGPUImageView.getGPUImage().deleteImage();
        mAdjustGPUImageView.setImage(getSrcBitmap());
        mActivity.showTopView();
        mActivity.doHideOperationBarAnim();
    }

    private void resetWithoutAnim(int id) {
        if (id == R.id.onekey_beauty_button) {
            if (mTask != null && !mTask.isCancelled()) {
                mTask.cancel(true);
            }
            mHandler.removeMessages(START_ANIMATION);
            mHandler.removeMessages(ONE_KEY_BEAUTY);
            mHandler.removeMessages(STOP_ANIMATION);
            if (mAnimatorView != null) {
                mAnimatorView.stopLoading();
            }
            if (mLightAnimSet != null && mLightAnimSet.isRunning()) {
                mLightAnimSet.cancel();
            }
            mAdjustGPUImageView.setFilter(mDefaultFilter);
            setSrcBitmap(getSrcBitmap());
            mOneKeyLayout.setVisibility(GONE);
            mCacheBitmap = null;
            mIsDealOver = false;
            mBitmapDealOver = false;
            mStartAnimation = false;
            mStopAnimation = false;
        } else if (id == R.id.whitening_beauty_button) {
            mWhiteningSeekbar.setProgress(50);//默认值
            mWhitenBrushView.reset();
            mWhitenSwitchPaint.setSelected(true);
            mWhitenSwitchEarse.setSelected(false);
            mWhitenSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mWhitenSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mWhiteningLayout.setVisibility(GONE);
        } else if (id == R.id.complexion_beauty_button) {
            mAdjustGPUImageView.setFilter(mDefaultFilter);
            setSrcBitmap(getSrcBitmap());
            mComplexionLayout.setVisibility(GONE);
        } else if (id == R.id.mopi_beauty_button) {
            if (mTask != null && !mTask.isCancelled()) {
                mTask.cancel(true);
            }
            mHandler.removeMessages(START_ANIMATION);
            mHandler.removeMessages(MOPI);
            mHandler.removeMessages(STOP_ANIMATION);
            if (mAnimatorView != null) {
                mAnimatorView.stopLoading();
            }
            mCacheBitmap = null;
            mIsDealOver = false;
            mBitmapDealOver = false;
            mStartAnimation = false;
            mStopAnimation = false;
            mMopiSeekbar.setProgress(50);//默认值
            mMopiBrushView.reset();
            mMopiSwitchPaint.setSelected(true);
            mMopiSwitchEarse.setSelected(false);
            mMopiSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mMopiSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mMopiLayout.setVisibility(GONE);
        } else if (id == R.id.hair_beauty_button) {
            mHairStrokenSeekbar.setProgress(50);//默认值
            mHairColorAdapter.setSelectedPosition(0);
            mHairColorView.reset();
            /*mSwitchEarse.setChecked(false);
            mSwitchPaint.setChecked(true);*/
            mHairSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mHairSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mHairLayout.setVisibility(GONE);
        } else if (id == R.id.lip_beauty_button) {
            mLipStrokenSeekbar.setProgress(50);//默认值
            mLipColorAdapter.setSelectedPosition(0);
            mLipView.reset();
            mLipSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mLipSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mLipLayout.setVisibility(GONE);
        } else if (id == R.id.eyes_beauty_button) {
            mBigEyesView.reset();
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mEyesLayout.setVisibility(GONE);
        } else if (id == R.id.tail_beauty_button) {
            mTailView.reset();
            mReset.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mTailLayout.setVisibility(GONE);
        } else if (id == R.id.whiten_teeth_button) {
            mWhitenTeethStrokenSeekbar.setProgress(50);//默认值
            mWhitenTeethView.reset();
            mWhitenTeethSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mWhitenTeethSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mWhitenTeethLayout.setVisibility(GONE);
        } else if (id == R.id.repair_button) {
            mRepairView.reset();
            mUndo.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mRepairLayout.setVisibility(GONE);
        } else if (id == R.id.boobjob_beauty_button) {
            mBreastView.reset();
            mBoobJobSeekbar.setProgress(0);
            mReset.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mBoobJobLayout.setVisibility(GONE);
        } else if (id == R.id.buttocks_beauty_button) {
            mButtocksView.reset();
            mButtocksSeekbar.setProgress(50);
            mReset.setVisibility(GONE);
            mSwitch.setVisibility(GONE);
            mButtocksLayout.setVisibility(GONE);
        } else {//重置界面 保存状态不变
            mCurId = -1;
            mHairColorView.setVisibility(GONE);
            mLipView.setVisibility(GONE);
            mBigEyesView.setVisibility(GONE);
            mTailView.setVisibility(GONE);
            mRepairView.setVisibility(GONE);
            mWhitenTeethView.setVisibility(GONE);
            mWhitenBrushView.setVisibility(GONE);
            mMopiBrushView.setVisibility(GONE);
            mBreastView.setVisibility(GONE);
            mButtocksView.setVisibility(GONE);
            mAdjustGPUImageView.setVisibility(VISIBLE);
            mButtonScrollView.setVisibility(VISIBLE);
            mAdjustGPUImageView.getGPUImage().deleteImage();
            mAdjustGPUImageView.setImage(getSrcBitmap());
        }
    }

    public void resetWithoutAnimation() {
        mCurId = -1;
        selectTab(-1);
        mAdjustGPUImageView.getGPUImage().deleteImage();
        mAdjustGPUImageView.setImage(getSrcBitmap());
    }

    /**
     * 重置  重置后所有状态恢复
     */
    public void reset() {
        mIsNeedSave = false;
        reset(-1);
    }

    public void resetNeedSave(boolean needSave) {
        mIsNeedSave = needSave;
    }

    @Override
    public boolean onConfirmClick() {
        deleteFloatingWindow();
        if (mActivity.isNeedGoToBeauty()) {
            if (mCurId == R.id.onekey_beauty_button) {
                mActivity.showLoading();
                ThreadPool.runOnNonUIThread(new Runnable() {
                    @Override
                    public void run() {
                        final Bitmap destBitmap = mAdjustGPUImageView.getCurrentBitmap(mSrcBitmap, mOneKeyAdjuster.getNewFilter());
                        ThreadPool.runUITask(new Runnable() {
                            @Override
                            public void run() {
                                mActivity.hideLoading();
                                setSrcBitmap(destBitmap);
                                mIsNeedSave = true;
                                mRetouchUsed = true;
                                mActivity.setConfirmEnable(true);
                                resetWithoutAnim(R.id.onekey_beauty_button);
                                mOneKeySeekBt.setCurSelectIndex(1, false);
                                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                                mActivity.refreshBitmapOfBeauty();
                                resetTotal();
                                CameraDrawable cd = new CameraDrawable(getResources(), destBitmap);
                                mActivity.updateSrcBitmapOfEdit(cd);
                            }
                        });
                    }
                });
                mActivity.setNeedSave(mIsNeedSave);
                return false;
            } else if (mCurId == R.id.whitening_beauty_button) {
                Bitmap finalBitmap = mWhitenBrushView.getFinalResult(true);
                setSrcBitmap(finalBitmap);
                mIsNeedSave = true;
                mGlowUsed = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.whitening_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else if (mCurId == R.id.complexion_beauty_button) {
                mActivity.showLoading();
                ThreadPool.runOnNonUIThread(new Runnable() {
                    @Override
                    public void run() {
                        final Bitmap destBitmap = mAdjustGPUImageView.getCurrentBitmap(mSrcBitmap, mComplexionAdjuster.getNewFilter());
                        ThreadPool.runUITask(new Runnable() {
                            @Override
                            public void run() {
                                mActivity.hideLoading();
                                setSrcBitmap(destBitmap);
                                mIsNeedSave = true;
                                mBlushUsed = true;
                                mActivity.setConfirmEnable(true);
                                resetWithoutAnim(R.id.complexion_beauty_button);
                                mComplexionSeekbar.setProgress(50);
                                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                                mActivity.refreshBitmapOfBeauty();
                                resetTotal();
                                CameraDrawable cd = new CameraDrawable(getResources(), destBitmap);
                                mActivity.updateSrcBitmapOfEdit(cd);
                            }
                        });
                    }
                });
                mActivity.setNeedSave(mIsNeedSave);
                return false;
            } else if (mCurId == R.id.mopi_beauty_button) {
                Bitmap finalBitmap = mMopiBrushView.getFinalResult(true);
                if (mMopiBrushView.isCreate()) {
                    setSrcBitmap(finalBitmap);
                }
                mIsNeedSave = true;
                mSmoothUsed = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.mopi_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else if (mCurId == R.id.hair_beauty_button) {
                Bitmap finalBitmap = mHairColorView.getFinalResult(true);
                setSrcBitmap(finalBitmap);
                mIsNeedSave = true;
                mHairColorUsed = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.hair_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else if (mCurId == R.id.lip_beauty_button) {
                Bitmap finalBitmap = mLipView.getFinalResult(true);
                setSrcBitmap(finalBitmap);
                mIsNeedSave = true;
                mLipstickUsed = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.lip_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else if (mCurId == R.id.eyes_beauty_button) {
                Bitmap finalBitmap = mBigEyesView.getCurBitmap();
                setSrcBitmap(finalBitmap);
                mIsNeedSave = true;
                mEyeTuneUsed = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.eyes_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                mEyesSeekbar.setProgress(20);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else if (mCurId == R.id.tail_beauty_button) {
                Bitmap finalBitmap = mTailView.getCurBitmap();
                setSrcBitmap(finalBitmap);
                mIsNeedSave = true;
                mTallerUsed = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.tail_beauty_button);
                mTailSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else if (mCurId == R.id.whiten_teeth_button) {
                Bitmap finalBitmap = mWhitenTeethView.getFinalResult(true);
                setSrcBitmap(finalBitmap);
                mIsNeedSave = true;
                mWhitenUsed = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.whiten_teeth_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else if (mCurId == R.id.repair_button) {
                Bitmap finalBitmap = mRepairView.getCurBitmap();
                setSrcBitmap(finalBitmap);
                mIsNeedSave = true;
                mHealingUsed = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.repair_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                mRepairSeekBar.setProgress(50);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else if (mCurId == R.id.boobjob_beauty_button) {
                Bitmap finalBitmap = mBreastView.getCurBitmap();
                setSrcBitmap(finalBitmap);
                mBoobjobUsed = true;
                mIsNeedSave = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.boobjob_beauty_button);
                mBoobJobSeekbar.setProgress(0);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else if (mCurId == R.id.buttocks_beauty_button) {
                Bitmap finalBitmap = mButtocksView.getCurBitmap();
                setSrcBitmap(finalBitmap);
                mButtocksUsed = true;
                mIsNeedSave = true;
                mActivity.setConfirmEnable(true);
                resetWithoutAnim(R.id.buttocks_beauty_button);
                mButtocksSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
                CameraDrawable cd = new CameraDrawable(getResources(), finalBitmap);
                mActivity.updateSrcBitmapOfEdit(cd);
            } else {
                return false;
            }
            mActivity.setNeedSave(mIsNeedSave);
            return true;
        } else {
            if (mCurId == R.id.onekey_beauty_button) {
                if (!AppVipManager.isVip()) {
                    mCheck2Save = true;
                    mActivity.setBackFromVipTool();
                    SVipController.showSubscribeActivity(mActivity, SVipConstant.VIP_ENTRANCE_EDIT, StatisticsConstant.ENTRANCE_VALUE_BEAUTY);
                    return false;
                }
                mActivity.showLoading();
                ThreadPool.runOnNonUIThread(new Runnable() {
                    @Override
                    public void run() {
                        final Bitmap destBitmap = mAdjustGPUImageView.getCurrentBitmap(mSrcBitmap, mOneKeyAdjuster.getNewFilter());
                        ThreadPool.runUITask(new Runnable() {
                            @Override
                            public void run() {
                                mActivity.hideLoading();
                                setSrcBitmap(destBitmap);
                                mIsNeedSave = true;
                                mRetouchUsed = true;
                                mActivity.setConfirmEnable(true);
                                reset(R.id.onekey_beauty_button);
                                mOneKeySeekBt.setCurSelectIndex(1, false);
                                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                                reset(-1);
                            }
                        });
                    }
                });
            } else if (mCurId == R.id.whitening_beauty_button) {
                setSrcBitmap(mWhitenBrushView.getFinalResult(true));
                mIsNeedSave = true;
                mGlowUsed = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.whitening_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.complexion_beauty_button) {
                mActivity.showLoading();
                ThreadPool.runOnNonUIThread(new Runnable() {
                    @Override
                    public void run() {
                        final Bitmap destBitmap = mAdjustGPUImageView.getCurrentBitmap(mSrcBitmap, mComplexionAdjuster.getNewFilter());
                        ThreadPool.runUITask(new Runnable() {
                            @Override
                            public void run() {
                                mActivity.hideLoading();
                                setSrcBitmap(destBitmap);
                                mIsNeedSave = true;
                                mBlushUsed = true;
                                mActivity.setConfirmEnable(true);
                                reset(R.id.complexion_beauty_button);
                                mComplexionSeekbar.setProgress(50);
                                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                                reset(-1);
                            }
                        });
                    }
                });
            } else if (mCurId == R.id.mopi_beauty_button) {
                if (!AppVipManager.isVip()) {
                    mCheck2Save = true;
                    mActivity.setBackFromVipTool();
                    SVipController.showSubscribeActivity(mActivity, SVipConstant.VIP_ENTRANCE_EDIT, StatisticsConstant.ENTRANCE_VALUE_BEAUTY);
                    return false;
                }
                if (mMopiBrushView.isCreate()) {
                    setSrcBitmap(mMopiBrushView.getFinalResult(true));
                }
                mIsNeedSave = true;
                mSmoothUsed = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.mopi_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.hair_beauty_button) {
                setSrcBitmap(mHairColorView.getFinalResult(true));
                mIsNeedSave = true;
                mHairColorUsed = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.hair_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.lip_beauty_button) {
                setSrcBitmap(mLipView.getFinalResult(true));
                mIsNeedSave = true;
                mLipstickUsed = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.lip_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.eyes_beauty_button) {
                setSrcBitmap(mBigEyesView.getCurBitmap());
                mIsNeedSave = true;
                mEyeTuneUsed = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.eyes_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                mEyesSeekbar.setProgress(20);
                reset(-1);
            } else if (mCurId == R.id.tail_beauty_button) {
                setSrcBitmap(mTailView.getCurBitmap());
                mIsNeedSave = true;
                mTallerUsed = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.tail_beauty_button);
                mTailSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.whiten_teeth_button) {
                if (!AppVipManager.isVip()) {
                    mCheck2Save = true;
                    mActivity.setBackFromVipTool();
                    SVipController.showSubscribeActivity(mActivity, SVipConstant.VIP_ENTRANCE_EDIT, StatisticsConstant.ENTRANCE_VALUE_BEAUTY);
                    return false;
                }
                setSrcBitmap(mWhitenTeethView.getFinalResult(true));
                mIsNeedSave = true;
                mWhitenUsed = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.whiten_teeth_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.repair_button) {
                if (!AppVipManager.isVip()) {
                    mCheck2Save = true;
                    mActivity.setBackFromVipTool();
                    SVipController.showSubscribeActivity(mActivity, SVipConstant.VIP_ENTRANCE_EDIT, StatisticsConstant.ENTRANCE_VALUE_BEAUTY);
                    return false;
                }
                setSrcBitmap(mRepairView.getCurBitmap());
                mIsNeedSave = true;
                mHealingUsed = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.repair_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                mRepairSeekBar.setProgress(50);
                reset(-1);
            } else if (mCurId == R.id.boobjob_beauty_button) {
                setSrcBitmap(mBreastView.getCurBitmap());
                mBoobjobUsed = true;
                mIsNeedSave = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.boobjob_beauty_button);
                mBoobJobSeekbar.setProgress(0);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.buttocks_beauty_button) {
                setSrcBitmap(mButtocksView.getCurBitmap());
                mButtocksUsed = true;
                mIsNeedSave = true;
                mActivity.setConfirmEnable(true);
                reset(R.id.buttocks_beauty_button);
                mButtocksSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else {
                return true;
            }
            mActivity.setNeedSave(mIsNeedSave);
            return false;
        }
    }

    private void statisticEyeDecorationUse(int id) {
        switch (id) {
            case R.id.bicep_button:
                mBicepUsed = true;
                break;
            default:
        }
    }

    private void statisticMuscleUse(int id) {
        switch (id) {
            case R.id.male_abs_button:
                mMaleAbsUsed = true;
                break;
            case R.id.pecs_button:
                mPecsUsed = true;
                break;
            case R.id.female_abs_button:
                mFemaleAbsUsed = true;
                break;
            default:
        }
    }

    @Override
    public boolean onCancelClick() {
        deleteFloatingWindow();
        mCheck2Save = false;
        if (mActivity.isNeedGoToBeauty()) {
            if (mCurId == R.id.onekey_beauty_button) {
                resetWithoutAnim(R.id.onekey_beauty_button);
                mOneKeySeekBt.setCurSelectIndex(1, false);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.whitening_beauty_button) {
                resetWithoutAnim(R.id.whitening_beauty_button);
                mWhiteningSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.complexion_beauty_button) {
                resetWithoutAnim(R.id.complexion_beauty_button);
                mComplexionSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.mopi_beauty_button) {
                resetWithoutAnim(R.id.mopi_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.hair_beauty_button) {
                resetWithoutAnim(R.id.hair_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.lip_beauty_button) {
                resetWithoutAnim(R.id.lip_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.eyes_beauty_button) {
                resetWithoutAnim(R.id.eyes_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                mEyesSeekbar.setProgress(20);
                resetTotal();
            } else if (mCurId == R.id.tail_beauty_button) {
                resetWithoutAnim(R.id.tail_beauty_button);
                mTailSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.whiten_teeth_button) {
                resetWithoutAnim(R.id.whiten_teeth_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.repair_button) {
                resetWithoutAnim(R.id.repair_button);
                mRepairSeekBar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.boobjob_beauty_button) {
                resetWithoutAnim(R.id.boobjob_beauty_button);
                mBoobJobSeekbar.setProgress(0);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else if (mCurId == R.id.buttocks_beauty_button) {
                resetWithoutAnim(R.id.buttocks_beauty_button);
                mButtocksSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                resetTotal();
            } else {
                if (!mActivity.isNeedGoToBeauty()) {
                    setSrcBitmap(null);//设置为空恢复原图
                    reset();
                }
                return true;
            }
            mActivity.setConfirmEnable(mIsNeedSave);
            mActivity.setNeedSave(mIsNeedSave);
        } else {
            mActivity.setConfirmEnable(mIsNeedSave);
            mActivity.setNeedSave(mIsNeedSave);
            if (mCurId == R.id.onekey_beauty_button) {
                reset(R.id.onekey_beauty_button);
                mOneKeySeekBt.setCurSelectIndex(1, false);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.whitening_beauty_button) {
                reset(R.id.whitening_beauty_button);
                mWhiteningSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.complexion_beauty_button) {
                reset(R.id.complexion_beauty_button);
                mComplexionSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.mopi_beauty_button) {
                reset(R.id.mopi_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.hair_beauty_button) {
                reset(R.id.hair_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.lip_beauty_button) {
                reset(R.id.lip_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.eyes_beauty_button) {
                reset(R.id.eyes_beauty_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                mEyesSeekbar.setProgress(20);
                reset(-1);
            } else if (mCurId == R.id.tail_beauty_button) {
                reset(R.id.tail_beauty_button);
                mTailSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.whiten_teeth_button) {
                reset(R.id.whiten_teeth_button);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.repair_button) {
                reset(R.id.repair_button);
                mRepairSeekBar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.boobjob_beauty_button) {
                reset(R.id.boobjob_beauty_button);
                mBoobJobSeekbar.setProgress(0);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else if (mCurId == R.id.buttocks_beauty_button) {
                reset(R.id.buttocks_beauty_button);
                mButtocksSeekbar.setProgress(50);
                mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                reset(-1);
            } else {
                if (!mActivity.isNeedGoToBeauty()) {
                    setSrcBitmap(null);//设置为空恢复原图
                    reset();
                }
                return true;
            }
        }
        return false;
    }

    private AlertDialog mExitAlertDialog;

    private void showExitAlertDialog() {
        if (mExitAlertDialog == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
            builder.setNegativeButton(R.string.image_edit_exit_dialog_cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mExitAlertDialog.dismiss();
                }
            });
            builder.setPositiveButton(R.string.image_edit_exit_dialog_save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (mCurId == R.id.male_abs_button) {
                        resetWithoutAnim(R.id.male_abs_button);
                        mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                        resetTotal();
                    } else if (mCurId == R.id.female_abs_button) {
                        resetWithoutAnim(R.id.female_abs_button);
                        mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                        resetTotal();
                    } else if (mCurId == R.id.pecs_button) {
                        resetWithoutAnim(R.id.pecs_button);
                        mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty, View.NO_ID);
                        resetTotal();
                    } else if (mCurId == R.id.bicep_button) {
                        resetWithoutAnim(R.id.bicep_button);
                        mActivity.showInsideBottomBarWithName(R.string.image_edit_beauty_bicep, View.NO_ID);
                        resetTotal();
                    }
                    mActivity.setConfirmEnable(mIsNeedSave);
                    mActivity.setNeedSave(mIsNeedSave);
                }
            });
            builder.setTitle(R.string.image_edit_exit_dialog_title);
            builder.setMessage(R.string.image_edit_exit_dialog_message);
            mExitAlertDialog = builder.create();
            mExitAlertDialog.setCancelable(true);
            mExitAlertDialog.setCanceledOnTouchOutside(false);
            mExitAlertDialog.show();
            FontUtil.setAlertDialogCustomFont(mExitAlertDialog);
        } else {
            mExitAlertDialog.show();
        }
    }

    @Override
    public void init() {
        mOneKeyBt.setOnClickListener(this);
        mMopiBt.setOnClickListener(this);
//        mWhiteningBt.setOnClickListener(this);
//        mComplexionBt.setOnClickListener(this);
        mHairBt.setOnClickListener(this);
        mEyesBt.setOnClickListener(this);
        mTailBt.setOnClickListener(this);
        mLipBt.setOnClickListener(this);
        mWhitenTeethBt.setOnClickListener(this);
        mRepairBt.setOnClickListener(this);
        mBoobJobBt.setOnClickListener(this);
        mButtocksBt.setOnClickListener(this);
        mFemaleAbsBt.setOnClickListener(this);
        mMaleAbsBt.setOnClickListener(this);
        mPecsBt.setOnClickListener(this);
        mBicepBt.setOnClickListener(this);
        initColor(getResources().getColor(R.color.windowBackgroundColor),
                getResources().getColor(R.color.accent_color));
        initDrawable();
        mButtonScrollView.setBeautyBarView(this);
        mButtonScrollView.setOnHorScrollChangeListener(new IndicativeHorizontalScrollView.HorizontalScrollChangeListener() {
            @Override
            public void onScroll(int l, int oldl) {
                if (mHorizontalItemWidth <= 0) {
                    getItemWidth();
                    return;
                }
                if (mBarItemCount <= 0) {
                    getBarItemCount();
                }
                mHorizontalBarScrollX = l;
            }
        });
    }

    public boolean isCheck2Save() {
        return mCheck2Save;
    }

    public void setCheck2Save(boolean check2Save) {
        mCheck2Save = check2Save;
    }


    @Override
    protected void onVisibilityChanged(@NonNull View changedView, int visibility) {
        super.onVisibilityChanged(changedView, visibility);
        if (visibility == VISIBLE) {
            updateVipStatus();
        }
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (mButtonScrollView != null) {
            mButtonScrollView.cancelStatisticTask();
        }
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        if (mHorizontalItemWidth <= 0) {
            getItemWidth();
            getBarItemCount();
        }
    }

    public float getHorizontalBarScrollX() {
        return mHorizontalBarScrollX;
    }

    public void statisticItemShow(float scrollX) {
        if (mHorizontalItemWidth <= 0 || mBarItemCount <= 0) {
            return;
        }
        float scrollCountF = scrollX / mHorizontalItemWidth;
        if ((int) scrollCountF != 0) {
            scrollCountF += mFraction;
        }
        int tmpTotalCount = 0;
        int scrollCountInt = (int) scrollCountF;
        if (scrollCountF - scrollCountInt > 0.5f) {
            if (scrollCountF - scrollCountInt > 0.6f) {
                tmpTotalCount = mBarItemCount + 1;
            } else {
                tmpTotalCount = mBarItemCount;
            }
            scrollCountInt++;
        } else if (scrollCountF - scrollCountInt < 0.05f && scrollCountF - scrollCountInt > 0) {
            tmpTotalCount = mBarItemCount + 1;
        } else {
            tmpTotalCount = mBarItemCount;
        }
        int lastIndex = mBarItemCount + scrollCountInt - 1;
        if (lastIndex >= mButtonLayout.getChildCount()) {
            lastIndex = mButtonLayout.getChildCount() - 1;
        }
        int startIndex = lastIndex - tmpTotalCount + 1;
        if (startIndex < 0) {
            startIndex = 0;
        }
        if (mStateType == TYPE_BEAUTY) {
            for (int i = startIndex; i <= lastIndex; i++) {
                statisticBeautyItemShow(i);
            }
        } else if (mStateType == TYPE_BODY) {
            for (int i = startIndex; i <= lastIndex; i++) {
                statisticBodyItemShow(i);
            }
        }
    }

    public void scrollHorListToStart() {
        if (mButtonScrollView != null) {
            mButtonScrollView.scrollTo(0, 0);
        }
        mHorizontalBarScrollX = 0;
    }


    private void statisticBeautyItemShow(int index) {
        switch (index) {
            case 0:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "retouch" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 1:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "smooth" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 2:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "hair dye" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 9:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "healing" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 7:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "whiten" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 8:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "eye tune" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 3:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "lip stick" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 4:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "eye shadow" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 5:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "eye lash" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 6:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BEAUTY + UMENG_CUSTOM_UNDER_LINE + "contact lense" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            default:
        }
    }

    private void statisticBodyItemShow(int index) {
        switch (index) {
            case 2:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BODY + UMENG_CUSTOM_UNDER_LINE + "male abs" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 4:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BODY + UMENG_CUSTOM_UNDER_LINE + "pecs" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 6:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BODY + UMENG_CUSTOM_UNDER_LINE + "bicep" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 3:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BODY + UMENG_CUSTOM_UNDER_LINE + "famale abs" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 0:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BODY + UMENG_CUSTOM_UNDER_LINE + "boob job" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 1:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BODY + UMENG_CUSTOM_UNDER_LINE + "buttocks" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            case 5:
                StatisticsUtils.statisicsCustomFunction(UMENG_CUSTOM_EVENT_EDITOR, UMENG_CUSTOM_KEY_FUNCTION,
                        MAIN_BTN_BODY + UMENG_CUSTOM_UNDER_LINE + "taller" + UMENG_CUSTOM_EVENT_FUNC_SHOW);
                break;
            default:
        }
    }

    private void getItemWidth() {
        if (mFlOneKey.getVisibility() == VISIBLE) {
            mHorizontalItemWidth = mFlOneKey.getMeasuredWidth();
        } else if (mFlMaleAbs.getVisibility() == VISIBLE) {
            mHorizontalItemWidth = mFlMaleAbs.getMeasuredWidth();
        }
    }

    private void getBarItemCount() {
        if (mHorizontalItemWidth <= 0) {
            mBarItemCount = -1;
            return;
        }
        float countF = DeviceUtils.getScreenWidthPx() * 1f / mHorizontalItemWidth;
        mBarItemCount = (int) (DeviceUtils.getScreenWidthPx() * 1f / mHorizontalItemWidth);
        mFraction = countF - mBarItemCount;
        /*if (countF - mBarItemCount > 0.5f) {
            mBarItemCount++;
        }*/

    }

    /**
     * 初始化一键美颜
     */
    private void initOneKeyBeautyLayout() {
        if (mOneKeyLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.onekey_beauty_stub);
            mOneKeyLayout = viewStub.inflate();
            mOneKeySeekBt = (CustomSeekButton) mOneKeyLayout.findViewById(R.id.seekbt);
            Resources res = getResources();
            CustomSeekButton.Builder builder = new CustomSeekButton.Builder()
                    .addButton(res.getString(R.string.image_edit_beauty_onekey_beauty_range_1))
                    .addButton(res.getString(R.string.image_edit_beauty_onekey_beauty_range_2))
                    .addButton(res.getString(R.string.image_edit_beauty_onekey_beauty_range_3));
            mOneKeySeekBt.create(builder);
            mOneKeySeekBt.setCurSelectIndex(1, false);
            mOneKeySeekBt.setSelectedListener(new CustomSeekButton.ISelectListener() {
                @Override
                public boolean onSelected(boolean user, int index) {
                    if (user) {
                        if (mIsDealOver) {
                            mCacheBitmap = null;
                            mIsDealOver = false;
                            mBitmapDealOver = false;
                            mStartAnimation = false;
                            mStopAnimation = false;
                            mHandler.sendEmptyMessageDelayed(START_ANIMATION, 200);//启动动画
                            mHandler.sendEmptyMessageDelayed(ONE_KEY_BEAUTY, 400);//进行磨皮
                            mActivity.setConfirmEnable(false);
                        } else {
                            return false;
                        }
                    }
                    return true;
                }
            });
            initDrawable();
        }
    }

    /**
     * 初始化磨皮
     */
    private void initMopiLayout() {
        if (mMopiLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.mopi_beauty_stub);
            mMopiLayout = viewStub.inflate();
            mMopiSeekbar = (CustomSizeSeekBar) mMopiLayout.findViewById(R.id.mopi_stroken_seekbar);
            mMopiSwitchPaint = (ImageView) mMopiLayout.findViewById(R.id.mopi_switch_paint);
            mMopiSwitchEarse = (ImageView) mMopiLayout.findViewById(R.id.mopi_switch_earse);

            mMopiBrushView.setStrokenChangeListener(new IStrokenChangeListener() {
                @Override
                public void onStrokenSizeChanged(int size) {
                    if (mCurId == R.id.mopi_beauty_button) {
                        if (size == 0) {
                            mUndo.setVisibility(GONE);
                            mSwitch.setVisibility(GONE);
                        } else {
                            mUndo.setVisibility(VISIBLE);
                            mSwitch.setVisibility(VISIBLE);
                        }
                    }
                }
            });
            mMopiSwitchPaint.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (mCurId == R.id.mopi_beauty_button) {
                        boolean showEffect = true;
                        switch (event.getAction()) {
                            case MotionEvent.ACTION_CANCEL:
                            case MotionEvent.ACTION_UP:
                                showEffect = false;
                                break;
                        }
                        if (mMopiSwitchPaint.isSelected()) {
                            mMopiBrushView.showEffectMask(showEffect);
                        }
                    }
                    return false;
                }
            });

            mMopiSeekbar.setProgress(50);//默认值
            mMopiSeekbar.setOnSeekBarChangeListener(mMopiBrushView);
            mMopiSwitchPaint.setSelected(true);
            mMopiSwitchEarse.setSelected(false);
            mMopiSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mMopiSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mMopiSwitchPaint.setOnClickListener(this);
            mMopiSwitchEarse.setOnClickListener(this);
            initDrawable();
        }
    }

    /**
     * 初始化美白
     */
    private void initWhiteningLayout() {
        if (mWhiteningLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.brighten_beauty_stub);
            mWhiteningLayout = viewStub.inflate();
            mWhiteningSeekbar = (CustomSizeSeekBar) mWhiteningLayout.findViewById(R.id.whiten_stroken_seekbar);
            mWhitenSwitchPaint = (ImageView) mWhiteningLayout.findViewById(R.id.whiten_switch_paint);
            mWhitenSwitchEarse = (ImageView) mWhiteningLayout.findViewById(R.id.whiten_switch_earse);

            mWhitenBrushView.setStrokenChangeListener(new IStrokenChangeListener() {
                @Override
                public void onStrokenSizeChanged(int size) {
                    if (mCurId == R.id.whitening_beauty_button) {
                        if (size == 0) {
                            mUndo.setVisibility(GONE);
                            mSwitch.setVisibility(GONE);
                        } else {
                            mUndo.setVisibility(VISIBLE);
                            mSwitch.setVisibility(VISIBLE);
                        }
                    }
                }
            });
            mWhitenSwitchPaint.setOnTouchListener(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (mCurId == R.id.whitening_beauty_button) {
                        boolean showEffect = true;
                        switch (event.getAction()) {
                            case MotionEvent.ACTION_CANCEL:
                            case MotionEvent.ACTION_UP:
                                showEffect = false;
                                break;
                        }
                        if (mWhitenSwitchPaint.isSelected()) {
                            mWhitenBrushView.showEffectMask(showEffect);
                        }
                    }
                    return false;
                }
            });

            mWhiteningSeekbar.setProgress(50);//默认值
            mWhiteningSeekbar.setOnSeekBarChangeListener(mWhitenBrushView);
            mWhitenSwitchPaint.setSelected(true);
            mWhitenSwitchEarse.setSelected(false);
            mWhitenSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mWhitenSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mWhitenSwitchPaint.setOnClickListener(this);
            mWhitenSwitchEarse.setOnClickListener(this);
            initDrawable();
        }
    }

    /**
     * 初始化美肤
     */
    private void initComplexionLayout() {
        if (mComplexionLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.complexion_beauty_stub);
            mComplexionLayout = viewStub.inflate();
            mComplexionText1 = (TextView) mComplexionLayout.findViewById(R.id.text1);
            mComplexionText2 = (TextView) mComplexionLayout.findViewById(R.id.text2);
            FontUtil.setCustomFont(mComplexionText1, mComplexionText2);
            mComplexionSeekbar = (CustomNumSeekBar) mComplexionLayout.findViewById(R.id.seekbar);
            mComplexionSeekbar.setShowText(false);
            mComplexionSeekbar.setOnSeekBarChangeListener(new com.photoeditor.demo.ui.widget.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(CustomNumSeekBar seekBar, int progress, boolean fromUser) {
                    dealComplexion(progress);
                    mAdjustGPUImageView.requestRender();
                }

                @Override
                public void onStartTrackingTouch(CustomNumSeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(CustomNumSeekBar seekBar) {

                }
            });
            initDrawable();
        }
    }

    /**
     * 初始化换发色
     */
    private void initHairLayout() {
        if (mHairLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.hair_beauty_stub);
            mHairLayout = viewStub.inflate();
            mHairStrokenSeekbar = (CustomSizeSeekBar) mHairLayout.findViewById(R.id.hair_stroken_seekbar);
            /*mSwitchPaint = (CheckableImageView) mHairLayout.findViewById(R.id.switch_paint);
            mSwitchEarse = (CheckableImageView) mHairLayout.findViewById(R.id.switch_earse);*/
            mHairSwitchPaint = (ImageView) mHairLayout.findViewById(R.id.switch_paint);
            mHairSwitchEarse = (ImageView) mHairLayout.findViewById(R.id.switch_earse);
            mHairColorList = (HorizontalListView) mHairLayout.findViewById(R.id.hair_color_list);

            mHairColorView.setStrokenChangeListener(new IStrokenChangeListener() {
                @Override
                public void onStrokenSizeChanged(int size) {
                    if (mCurId == R.id.hair_beauty_button) {
                        if (size == 0) {
                            mUndo.setVisibility(GONE);
                            mSwitch.setVisibility(GONE);
                        } else {
                            mUndo.setVisibility(VISIBLE);
                            mSwitch.setVisibility(VISIBLE);
                        }
                    }
                }
            });
            mHairColorAdapter = new HairColorListAdapter(getContext(), HairColorConstant.getColorBgBean());
            mHairColorList.setAdapter(mHairColorAdapter);
            mHairColorList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    mHairColorAdapter.setSelectedPosition(position, view);
                    BgBean bgBean = mHairColorAdapter.getItem(position);
                    if (bgBean instanceof InsideResColorBean) {
                        InsideResColorBean colorBgBean = (InsideResColorBean) bgBean;
                        int color = colorBgBean.getColor();
                        mHairColorView.changeColor(color);
                    }
                }
            });
            mHairStrokenSeekbar.setProgress(50);//默认值
            mHairStrokenSeekbar.setOnSeekBarChangeListener(mHairColorView);
            mHairSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mHairSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mHairSwitchPaint.setOnClickListener(this);
            mHairSwitchEarse.setOnClickListener(this);
            initDrawable();
        }
    }


    /**
     * 初始化换嘴唇颜色
     */
    private void initLipLayout() {
        if (mLipLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.lip_beauty_stub);
            mLipLayout = viewStub.inflate();
            mLipStrokenSeekbar = (CustomSizeSeekBar) mLipLayout.findViewById(R.id.lip_stroken_seekbar);
            mLipSwitchPaint = (ImageView) mLipLayout.findViewById(R.id.lip_switch_paint);
            mLipSwitchEarse = (ImageView) mLipLayout.findViewById(R.id.lip_switch_earse);
            mLipColorList = (HorizontalListView) mLipLayout.findViewById(R.id.lip_color_list);

            mLipView.setStrokenChangeListener(new IStrokenChangeListener() {
                @Override
                public void onStrokenSizeChanged(int size) {
                    if (mCurId == R.id.lip_beauty_button) {
                        if (size == 0) {
                            mUndo.setVisibility(GONE);
                            mSwitch.setVisibility(GONE);
                        } else {
                            mUndo.setVisibility(VISIBLE);
                            mSwitch.setVisibility(VISIBLE);
                        }
                    }
                }
            });
            mLipColorAdapter = new HairColorListAdapter(getContext(), LipColorConstant.getColorBgBean());
            mLipColorList.setAdapter(mLipColorAdapter);
            mLipColorList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    mLipColorAdapter.setSelectedPosition(position, view);
                    BgBean bgBean = mLipColorAdapter.getItem(position);
                    if (bgBean instanceof InsideLipColorModeBean) {
                        InsideLipColorModeBean colorBgBean = (InsideLipColorModeBean) bgBean;
                        int color = colorBgBean.getColor();
                        mLipView.changeColor(color, colorBgBean.getOverlyingMode());
                    }
                }
            });
            mLipStrokenSeekbar.setProgress(50);//默认值
            mLipStrokenSeekbar.setOnSeekBarChangeListener(mLipView);
            mLipSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mLipSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mLipSwitchPaint.setOnClickListener(this);
            mLipSwitchEarse.setOnClickListener(this);
            initDrawable();
        }
    }

    /*
     * 初始化美白牙齿
     */
    private void initWhitenTeethLayout() {
        if (mWhitenTeethLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.whiten_teeth_beauty_stub);
            mWhitenTeethLayout = viewStub.inflate();
            mWhitenTeethStrokenSeekbar = (CustomSizeSeekBar) mWhitenTeethLayout.findViewById(R.id.whiten_teeth_stroken_seekbar);
            mWhitenTeethSwitchPaint = (ImageView) mWhitenTeethLayout.findViewById(R.id.whiten_teeth_switch_paint);
            mWhitenTeethSwitchEarse = (ImageView) mWhitenTeethLayout.findViewById(R.id.whiten_teeth_switch_earse);

            mWhitenTeethView.setStrokenChangeListener(new IStrokenChangeListener() {
                @Override
                public void onStrokenSizeChanged(int size) {
                    if (mCurId == R.id.whiten_teeth_button) {
                        if (size == 0) {
                            mUndo.setVisibility(GONE);
                            mSwitch.setVisibility(GONE);
                        } else {
                            mUndo.setVisibility(VISIBLE);
                            mSwitch.setVisibility(VISIBLE);
                        }
                    }
                }
            });

            mWhitenTeethStrokenSeekbar.setProgress(50);//默认值
            mWhitenTeethStrokenSeekbar.setOnSeekBarChangeListener(mWhitenTeethView);
            mWhitenTeethSwitchPaint.setImageResource(R.drawable.ic_tool_doodle_paint_light);
            mWhitenTeethSwitchEarse.setImageResource(R.drawable.ic_tool_doodle_rerser);
            mWhitenTeethSwitchPaint.setOnClickListener(this);
            mWhitenTeethSwitchEarse.setOnClickListener(this);
            initDrawable();
        }
    }

    /**
     * 初始化大眼
     */
    private void initEyesLayout() {
        if (mEyesLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.eyes_beauty_stub);
            mEyesLayout = viewStub.inflate();
            mEyesText1 = (TextView) mEyesLayout.findViewById(R.id.text1);
            mEyesText2 = (TextView) mEyesLayout.findViewById(R.id.text2);
            FontUtil.setCustomFont(mEyesText1, mEyesText2);
            mEyesSeekbar = (CustomNumSeekBar) mEyesLayout.findViewById(R.id.seekbar);
            mBigEyesView.setOperationListener(new IBigEyeOperationListener() {
                @Override
                public void onOperationSizeChanged(int size) {
                    if (mCurId == R.id.eyes_beauty_button) {
                        if (size == 0) {
                            mUndo.setVisibility(GONE);
                            mSwitch.setVisibility(GONE);
                        } else {
                            mUndo.setVisibility(VISIBLE);
                            mSwitch.setVisibility(VISIBLE);
                        }
                    }
                }
            });
            mEyesSeekbar.setOnSeekBarChangeListener(new com.photoeditor.demo.ui.widget.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(CustomNumSeekBar seekBar, int progress, boolean fromUser) {
                    mBigEyesView.setProgress(progress);
                }

                @Override
                public void onStartTrackingTouch(CustomNumSeekBar seekBar) {
                    mBigEyesView.setDrawCenterCircle(true);
                }

                @Override
                public void onStopTrackingTouch(CustomNumSeekBar seekBar) {
                    mBigEyesView.setDrawCenterCircle(false);
                }
            });
            initDrawable();
            mEyesSeekbar.setProgress(20);
        }
    }

    /**
     * 初始化增高
     */
    private void initTailLayout() {
        if (mTailLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.tail_beauty_stub);
            mTailLayout = viewStub.inflate();
            mTailSeekbar = (CustomNumSeekBar) mTailLayout.findViewById(R.id.seekbar);
            mTailSeekbar.setOnSeekBarChangeListener(new com.photoeditor.demo.ui.widget.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(CustomNumSeekBar seekBar, int progress, boolean fromUser) {
                    if (fromUser) {//用户拖动的
                        final int maxProgressOrCur = mTailView.setProgress(progress);
                        if (maxProgressOrCur != progress) {//已经拉伸到最大值, 最大值为maxProgressOrCur
                            mTailSeekbar.setProgress(maxProgressOrCur);
                            if (mTailView.isMin()) {
                            } else {
                            }
                        }
                        if (mTailView.isChanged()) {
                            mSwitch.setVisibility(View.VISIBLE);
                            mReset.setVisibility(View.VISIBLE);
                        }
                    }
                }

                @Override
                public void onStartTrackingTouch(CustomNumSeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(CustomNumSeekBar seekBar) {

                }
            });
            initDrawable();
            FontUtil.setCustomFont((TextView) mTailLayout.findViewById(R.id.text_left), (TextView) mTailLayout.findViewById(R.id.text_right));
            mTailView.setProgressListener(new TailImageView.IProgressListener() {
                @Override
                public void onProgress(int progress) {
                    mTailSeekbar.setProgress(progress);
                }
            });
        }
    }

    private void initBoobJobLayout() {
        if (mBoobJobLayout == null) {
            ViewStub viewStub = findViewById(R.id.boobjob_beauty_stub);
            mBoobJobLayout = viewStub.inflate();
            mBoobJobSeekbar = mBoobJobLayout.findViewById(R.id.seekbar);
            mBoobJobSeekbar.setShowText(false);
            mBoobJobSeekbar.setProgress(0);
            mBoobJobSeekbar.setOnSeekBarChangeListener(new com.photoeditor.demo.ui.widget.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(CustomNumSeekBar seekBar, int progress, boolean fromUser) {
                    if (mSwitch.getVisibility() == GONE) {
                        mSwitch.setVisibility(VISIBLE);
                    }
                }

                @Override
                public void onStartTrackingTouch(CustomNumSeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(CustomNumSeekBar seekBar) {
                    mBreastView.setProgress(seekBar.getProgress());
                }
            });
            initDrawable();

        }
    }

    private void initButtocksLayout() {
        if (mButtocksLayout == null) {
            ViewStub viewStub = findViewById(R.id.buttocks_beauty_stub);
            mButtocksLayout = viewStub.inflate();
            mButtocksSeekbar = mButtocksLayout.findViewById(R.id.seekbar);
            mButtocksSeekbar.setProgress(50);
            mButtocksSeekbar.setOnSeekBarChangeListener(new com.photoeditor.demo.ui.widget.OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(CustomNumSeekBar seekBar, int progress, boolean fromUser) {
                    if (mSwitch.getVisibility() == GONE) {
                        mSwitch.setVisibility(VISIBLE);
                    }
                }

                @Override
                public void onStartTrackingTouch(CustomNumSeekBar seekBar) {

                }

                @Override
                public void onStopTrackingTouch(CustomNumSeekBar seekBar) {
                    mButtocksView.setProgress(seekBar.getProgress());
                }
            });
            initDrawable();

        }
    }

    private String[] parseLeftRightDownUrl(String url, String rootUrl) {
        String[] leftRight = null;
        String downUrl = StoreOnlineBean.removeQueryString(url);
        rootUrl = StoreOnlineBean.removeQueryString(rootUrl);
        String[] tmp = downUrl.split("#");
        if (tmp.length == 2) {
            leftRight = new String[2];
            leftRight[0] = tmp[0];
            leftRight[1] = rootUrl + File.separator + tmp[1];
        }
        return leftRight;
    }

    private void initRepairLayout() {
        if (mRepairLayout == null) {
            ViewStub viewStub = (ViewStub) findViewById(R.id.repair_stub);
            mRepairLayout = viewStub.inflate();
            mRepairSeekBar = (CustomSizeSeekBar) mRepairLayout.findViewById(R.id.repair_seekbar);
            mRepairView.setOperationListener(new RepairView.IRepairListener() {
                @Override
                public void onOperationSizeChanged(int historySize, int effectStep) {
                    if (mCurId == R.id.repair_button) {
                        if (historySize == 0) {
                            mUndo.setVisibility(GONE);
                            mSwitch.setVisibility(GONE);
                        } else {
                            mUndo.setVisibility(VISIBLE);
                            mSwitch.setVisibility(VISIBLE);
                        }
                    }
                }
            });
            mRepairSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                @Override
                public void onProgressChanged(CustomSizeSeekBar seekBar, int progress, boolean fromUser) {
                    if (mCurId == R.id.repair_button) {
                        mRepairView.setProgress(progress);
                    }
                }

                @Override
                public void onStartTrackingTouch(CustomSizeSeekBar seekBar) {
                    if (mCurId == R.id.repair_button) {
                        mRepairView.setDrawCenterCircle(true);
                    }
                }

                @Override
                public void onStopTrackingTouch(CustomSizeSeekBar seekBar) {
                    if (mCurId == R.id.repair_button) {
                        mRepairView.setDrawCenterCircle(false);
                    }
                }
            });
            initDrawable();
            FontUtil.setCustomFont((TextView) mRepairLayout.findViewById(R.id.text_left), (TextView) mRepairLayout.findViewById(R.id.text_right));
            mRepairSeekBar.setProgress(50);
        }
    }

    public AdjustGPUImageView getAdjustGPUImageView() {
        return mAdjustGPUImageView;
    }

    public void setmAdjustGPUImageView(AdjustGPUImageView adjustGPUImageView) {
        mAdjustGPUImageView = adjustGPUImageView;
    }

    public void setHairColorView(Color_view hairColorView) {
        this.mHairColorView = hairColorView;
    }

    public void setLipColorView(LipView lipView) {
        this.mLipView = lipView;
    }

    public void setBigEyesView(BigEyesView bigEyesView) {
        this.mBigEyesView = bigEyesView;
    }

    public void setReapirView(RepairView repairView) {
        this.mRepairView = repairView;
    }

    public void setWhiteTeethView(BrushView brushView) {
        this.mWhitenTeethView = brushView;
    }

    public void setMopiView(MopiBrushView brushView) {
        this.mMopiBrushView = brushView;
    }

    public void setWhitenView(WhitenBrushView brushView) {
        this.mWhitenBrushView = brushView;
    }

    public void setTailView(TailImageView tailView) {
        this.mTailView = tailView;
    }

    public void setImageViewCover(ImageView imageViewCover) {
        mImageViewCover = imageViewCover;
    }

    public void setBreastView(BreastView view) {
        mBreastView = view;
    }

    public void setButtocksView(BreastView view) {
        mButtocksView = view;
    }

    public void setAnimatorView(LoadingView animatorView, View lightAnimView) {
        mAnimatorView = animatorView;
        mLightAnimView = lightAnimView;
    }

    /**
     * 磨皮开始
     *
     * @param isOnekeyBeauty
     */
    private void doMopi(final boolean isOnekeyBeauty) {
        mTask = new AsyncTask<Object, Void, Bitmap>() {
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
            }

            @Override
            protected Bitmap doInBackground(Object... params) {
                Bitmap bitmap = null;
                try {
                    Bitmap srcBitmap = (Bitmap) params[0];
                    int progress = (Integer) params[1];
                    if (srcBitmap != null && !srcBitmap.isRecycled()) {
                        bitmap = BeautifyMultiThread.beautifyImg(srcBitmap, (int) (progress / 100f * 20));
                    }
                } catch (OutOfMemoryError e) {
                    System.gc();
                }
                return bitmap;
            }

            protected void onPostExecute(Bitmap result) {
                super.onPostExecute(result);
                if (getVisibility() == VISIBLE) {
                    mBitmapDealOver = true;
                    if (isOnekeyBeauty) {
                        mCacheBitmap = result;
                        dealOneKeyBeauty();
                    } else {
                        mMopiBrushView.setEffectBitmap(result);
                    }
                    if (!mStopAnimation && mStartAnimation) {
                        mStopAnimation = true;
                        mHandler.sendEmptyMessageDelayed(STOP_ANIMATION, 100);
                    }
                }
            }

            ;
        }.execute(getSrcBitmap(), isOnekeyBeauty ? getOneKeyBeautyProgress() : MopiBrushView.EFFECT_PERCENTAGE);
    }

    /**
     * 处理Touch
     *
     * @param v
     * @param event
     */
    public boolean dealOnTouch(View v, MotionEvent event) {
        if (mCurId == R.id.onekey_beauty_button || mCurId == R.id.complexion_beauty_button) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                mAdjustGPUImageView.setVisibility(View.GONE);
                mImageViewCover.setVisibility(View.VISIBLE);
                return true;
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                mImageViewCover.setVisibility(View.GONE);
                mAdjustGPUImageView.setVisibility(View.VISIBLE);
                return true;
            }
        }
        return false;
    }

    public Bitmap getCurrentBitmap() {
        if (mIsNeedSave) {
            Bitmap bitmap = mSrcBitmap;
            /*try {
                System.gc();
                bitmap = mAdjustGPUImageView.getCurrentBitmap();
            } catch (Exception e) {
            }*/

            return bitmap;
        }
        return null;
    }

    public Bitmap getSrcBitmap() {
        if (mSrcBitmap != null) {
            return mSrcBitmap;
        } else {
            return mActivity.getSrcBitmap();
        }
    }

    /**
     * 设置进入时的图片
     *
     * @param srcBitmap
     */
    public void setSrcBitmap(Bitmap srcBitmap) {
        if (srcBitmap != null && mSrcBitmap != null && (mSrcBitmap.getHeight() != srcBitmap.getHeight() || mSrcBitmap.getWidth() != srcBitmap.getWidth())) {
            mActivity.resetGPUImageView(new int[]{srcBitmap.getWidth(), srcBitmap.getHeight()});
        }
        this.mSrcBitmap = srcBitmap;
        if (mSrcBitmap != null) {
            mAdjustGPUImageView.getGPUImage().deleteImage();
            mAdjustGPUImageView.setImage(mSrcBitmap);
        }
    }

    public void initColor(int primaryColor, int emphasisColor) {
        if (mComplexionLayout != null) {
            mComplexionSeekbar.setDefaultColorStyle(emphasisColor);
        }
        if (mTailLayout != null) {
            mTailSeekbar.setDefaultColorStyle(emphasisColor);
        }
        if (mEyesLayout != null) {
            mEyesSeekbar.setDefaultColorStyle(emphasisColor);
        }
    }

    public void initDrawable() {
        int textColor = getResources().getColor(R.color.image_edit_sencond_text_color);
        mButtonScrollView.setBackgroundResource(R.drawable.image_edit_sencond_bg);
        if (mOneKeyLayout != null) {
            mOneKeyLayout.setBackgroundResource(R.drawable.image_edit_sencond_bg);
        }

        if (mComplexionLayout != null) {
            mComplexionLayout.setBackgroundResource(R.drawable.image_edit_sencond_bg);
            mComplexionText1.setTextColor(textColor);
            mComplexionText2.setTextColor(textColor);
            mComplexionSeekbar.setNumBgTumb(getResources().getDrawable(R.drawable.bg_image_edit_seekbar_num));
//            mComplexionSeekbar.setTouchTumb(getResources().getDrawable(R.drawable.bg_image_edit_seekbar_touch));
            mComplexionSeekbar.setProgressTumb(getResources().getDrawable(R.drawable.ic_image_edit_seekbar_progress));
            mComplexionSeekbar.setProgressBgTumb(getResources().getDrawable(R.drawable.bg_image_edit_seekbar_progress));
            mComplexionSeekbar.setTextColor(getResources().getColor(R.color.white));
        }

        /*if(mHairLayout != null){
            mHairColorList.setBackgroundResource(R.drawable.image_edit_sencond_bg);
            mSwitchPaint.setImageDrawable(getResources().getDrawable(R.drawable.ic_tool_doodle_paint),
                    getResources().getDrawable(R.drawable.ic_tool_doodle_paint_light));
            *//*mSwitchPaint.setBackgroundDrawable(getResources().getDrawable(R.drawable.image_edit_tool_beauty_hair_switch_bg),
                    getResources().getDrawable(R.drawable.image_edit_tool_beauty_hair_switch_bg_selected));*//*
            mSwitchEarse.setImageDrawable(getResources().getDrawable(R.drawable.ic_tool_doodle_rerser),
                    getResources().getDrawable(R.drawable.ic_tool_doodle_rerser_light));
            *//*mSwitchEarse.setBackgroundDrawable(getResources().getDrawable(R.drawable.image_edit_tool_beauty_hair_switch_bg),
                    getResources().getDrawable(R.drawable.image_edit_tool_beauty_hair_switch_bg_selected));*//*
        }*/

        /* if(mLipLayout != null){
         *//*mLipColorList.setBackgroundResource(R.drawable.image_edit_sencond_bg);
            mLipSwitchPaint.setImageDrawable(getResources().getDrawable(R.drawable.ic_tool_doodle_paint),
                    getResources().getDrawable(R.drawable.ic_tool_doodle_paint));
            *//**//*mLipSwitchPaint.setBackgroundDrawable(getResources().getDrawable(R.drawable.image_edit_tool_beauty_hair_switch_bg),
                   getResources().getDrawable(R.drawable.image_edit_tool_beauty_hair_switch_bg_selected));*//**//*
            mLipSwitchEarse.setImageDrawable(getResources().getDrawable(R.drawable.ic_tool_doodle_rerser),
                    getResources().getDrawable(R.drawable.ic_tool_doodle_rerser));
            *//**//*mLipSwitchEarse.setBackgroundDrawable(getResources().getDrawable(R.drawable.image_edit_tool_beauty_hair_switch_bg),
                    getResources().getDrawable(R.drawable.image_edit_tool_beauty_hair_switch_bg_selected));*//*
        }*/

        if (mEyesLayout != null) {
            mEyesLayout.setBackgroundResource(R.drawable.image_edit_sencond_bg);
            mEyesText1.setTextColor(textColor);
            mEyesText2.setTextColor(textColor);
            mEyesSeekbar.setNumBgTumb(getResources().getDrawable(R.drawable.bg_image_edit_seekbar_num));
//            mEyesSeekbar.setTouchTumb(getResources().getDrawable(R.drawable.bg_image_edit_seekbar_touch));
            mEyesSeekbar.setProgressTumb(getResources().getDrawable(R.drawable.ic_image_edit_seekbar_progress));
            mEyesSeekbar.setProgressBgTumb(getResources().getDrawable(R.drawable.bg_image_edit_seekbar_progress));
            mEyesSeekbar.setTextColor(getResources().getColor(R.color.white));
        }

        if (mTailLayout != null) {
            mTailLayout.setBackgroundResource(R.drawable.image_edit_sencond_bg);

            mTailSeekbar.setNumBgTumb(getResources().getDrawable(R.drawable.bg_image_edit_seekbar_num));
//            mTailSeekbar.setTouchTumb(getResources().getDrawable(R.drawable.bg_image_edit_seekbar_touch));
            mTailSeekbar.setProgressTumb(getResources().getDrawable(R.drawable.ic_image_edit_seekbar_progress));
            mTailSeekbar.setProgressBgTumb(getResources().getDrawable(R.drawable.bg_image_edit_seekbar_progress));
            mTailSeekbar.setTextColor(getResources().getColor(R.color.white));
        }
        if (mBoobJobLayout != null) {
            mBoobJobLayout.setBackgroundResource(R.drawable.image_edit_sencond_bg);
        }
        if (mButtocksLayout != null) {
            mButtocksLayout.setBackgroundResource(R.drawable.image_edit_sencond_bg);
        }
        mOneKeyBt.setThemeImageRes(R.drawable.ic_tool_beauty_retouch, View.NO_ID);
//        mOneKeyBt.setBackgroundResource(R.drawable.image_edit_sencond_bg_selector);
        mHairBt.setThemeImageRes(R.drawable.ic_tool_beauty_long_hair, View.NO_ID);
//        mHairBt.setBackgroundResource(R.drawable.image_edit_sencond_bg_selector);
        mMopiBt.setThemeImageRes(R.drawable.ic_tool_beauty_smooth, View.NO_ID);
//        mMopiBt.setBackgroundResource(R.drawable.image_edit_sencond_bg_selector);
//        mWhiteningBt.setThemeImageRes(R.drawable.ic_tool_beauty_glow, View.NO_ID);
//        mComplexionBt.setThemeImageRes(R.drawable.ic_tool_beauty_blush, View.NO_ID);
        mEyesBt.setThemeImageRes(R.drawable.ic_tool_beauty_eyetune, View.NO_ID);
//        mEyesBt.setBackgroundResource(R.drawable.image_edit_sencond_bg_selector);
        mTailBt.setThemeImageRes(R.drawable.ic_tool_beauty_taller, View.NO_ID);
//        mTailBt.setBackgroundResource(R.drawable.image_edit_sencond_bg_selector);
        mLipBt.setThemeImageRes(R.drawable.ic_tool_beauty_lipstick, View.NO_ID);
//        mLipBt.setBackgroundResource(R.drawable.image_edit_sencond_bg_selector);
        mBoobJobBt.setThemeImageRes(R.drawable.icon_beauty_breasts, View.NO_ID);
        mButtocksBt.setThemeImageRes(R.drawable.icon_beauty_buttocks, View.NO_ID);
        mFemaleAbsBt.setThemeImageRes(R.drawable.icon_beauty_female_abs, View.NO_ID);
        mMaleAbsBt.setThemeImageRes(R.drawable.icon_beauty_male_abs, View.NO_ID);
        mPecsBt.setThemeImageRes(R.drawable.icon_beauty_pecs, View.NO_ID);
        mBicepBt.setThemeImageRes(R.drawable.icon_beauty_biceps, View.NO_ID);
    }

    public void switchToOneKeyBeauty() {
        mOneKeyBt.performClick();
    }

    public void switchToHairColor() {
        mHairBt.performClick();
    }

    public void switchToSmooth() {
        mMopiBt.performClick();
    }

    public void switchToSkinTone() {
//        mComplexionBt.performClick();
    }

    public void switchToBrighten() {
//        mWhiteningBt.performClick();
    }

    public void switchToBigEyes() {
        mEyesBt.performClick();
    }

    public void switchToTaller() {
        mTailBt.performClick();
    }

    public void switchToLip() {
        mLipBt.performClick();
    }

    /**
     * 处理美白
     *
     * @param progress
     */
    private void dealWhitening(int progress) {
        mWhitenAdjuster.adjustSkinColor(progress);
    }

    /**
     * 处理肤色
     *
     * @param progress
     */
    private void dealComplexion(int progress) {
        mComplexionAdjuster.whitening(progress);
    }

    /**
     * 处理一键美颜
     */
    private void dealOneKeyBeauty() {
        int progress = getOneKeyBeautyProgress();
        mOneKeyAdjuster.whitening(progress);
        mOneKeyAdjuster.adjustSkinColor(progress);
    }

    /**
     * 0-100之间
     *
     * @return
     */
    private int getOneKeyBeautyProgress() {
        if (mOneKeySeekBt.getCurSelectIndex() == 0) {
            return 20;
        } else if (mOneKeySeekBt.getCurSelectIndex() == 1) {
            return 50;
        } else if (mOneKeySeekBt.getCurSelectIndex() == 2) {
            return 75;
        }
        return 50;
    }

    private AnimatorSet mLightAnimSet;
    private View mLightAnimView;

    private void doLightAnim() {
        mLightAnimView.setVisibility(View.VISIBLE);
        ObjectAnimator alphaAnim1 = ObjectAnimator.ofFloat(mLightAnimView, "alpha", 0, 1);
        alphaAnim1.setDuration(858);
        ObjectAnimator scaleAnim1 = ObjectAnimator.ofFloat(mLightAnimView, "scaleX", 1f, 1.4f);
        scaleAnim1.setStartDelay(396);
        scaleAnim1.setDuration(1452);
        ObjectAnimator scaleAnim2 = ObjectAnimator.ofFloat(mLightAnimView, "scaleY", 1f, 1.4f);
        scaleAnim2.setStartDelay(396);
        scaleAnim2.setDuration(1452);
        ObjectAnimator alphaAnim2 = ObjectAnimator.ofFloat(mLightAnimView, "alpha", 1, 0);
        alphaAnim2.setStartDelay(1320);
        alphaAnim2.setDuration(528);
        mLightAnimSet = new AnimatorSet();
        mLightAnimSet.playTogether(alphaAnim1, scaleAnim1, scaleAnim2, alphaAnim2);
        mLightAnimSet.start();
        mLightAnimSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mLightAnimView.setVisibility(View.GONE);
                mHandler.sendEmptyMessage(STOP_ANIMATION);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                mLightAnimView.setVisibility(View.GONE);
                mHandler.sendEmptyMessage(STOP_ANIMATION);
            }
        });
    }

    public boolean isHasUseButtocks() {
        return mButtocksUsed;
    }

    public boolean isHasUseBoobJob() {
        return mBoobjobUsed;
    }

    public boolean isHasUseSmooth() {
        return mSmoothUsed;
    }

    public boolean isHasUseRetouch() {
        return mRetouchUsed;
    }

    public boolean isHasUseHairColor() {
        return mHairColorUsed;
    }

    public boolean isHealingUsed() {
        return mHealingUsed;
    }

    public boolean isHasWhitenUsed() {
        return mWhitenUsed;
    }

    public boolean isEyeTuneUsed() {
        return mEyeTuneUsed;
    }

    public boolean isLipStickeUsed() {
        return mLipstickUsed;
    }

    public boolean isEyeShadowUsed() {
        return mEyeShadowUsed;
    }

    public boolean isEyeLashUsed() {
        return mEyeLashUsed;
    }

    public boolean isContactLenseUsed() {
        return mContanctLenseUsed;
    }

    public boolean isBicepUsed() {
        return mBicepUsed;
    }

    public boolean isTallerUsed() {
        return mTallerUsed;
    }

    public boolean isMaleAbsUsed() {
        return mMaleAbsUsed;
    }

    public boolean isPecsUsed() {
        return mPecsUsed;
    }

    public boolean isFemaleAbsUsed() {
        return mFemaleAbsUsed;
    }

    public void resetBreastSeekBar() {
        if (mCurId == R.id.boobjob_beauty_button) {
            mBoobJobSeekbar.setProgress(0);
        } else if (mCurId == R.id.buttocks_beauty_button) {
            mButtocksSeekbar.setProgress(50);
        }
    }

    public void statisticsSave() {
        if (mRetouchUsed) {
            mActivity.statisticsMainBtnEditSave("retouch");
        }
        if (mHealingUsed) {
            mActivity.statisticsMainBtnEditSave("healing");
        }
        if (mWhitenUsed) {
            mActivity.statisticsMainBtnEditSave("whiten");
        }
        if (mSmoothUsed) {
            mActivity.statisticsMainBtnEditSave("smooth");
        }
        if (mGlowUsed) {
            mActivity.statisticsMainBtnEditSave("glow");
        }
        if (mHairColorUsed) {
            mActivity.statisticsMainBtnEditSave("hairColor");
        }
        if (mLipstickUsed) {
            mActivity.statisticsMainBtnEditSave("lipstick");
        }
        if (mBoobjobUsed) {
            mActivity.statisticsMainBtnEditSave("boobjob");
        }
        if (mButtocksUsed) {
            mActivity.statisticsMainBtnEditSave("buttocks");
        }
        if (mBlushUsed) {
            mActivity.statisticsMainBtnEditSave("blush");
        }
        if (mEyeTuneUsed) {
            mActivity.statisticsMainBtnEditSave("eyeTune");
        }
        if (mTallerUsed) {
            mActivity.statisticsMainBtnEditSave("taller");
        }
    }

    public void chageStateType(int type) {
        int visibleBeauty = 0;
        int visibleBoDy = 0;
        mStateType = type;
        if (type == TYPE_BEAUTY) {
            visibleBeauty = View.VISIBLE;
            visibleBoDy = View.GONE;
            mButtonScrollView.setType(TYPE_BEAUTY);
        } else {
            visibleBeauty = View.GONE;
            visibleBoDy = View.VISIBLE;
            mButtonScrollView.setType(TYPE_BODY);
        }

        mFlOneKey.setVisibility(visibleBeauty);
        mFlRepair.setVisibility(visibleBeauty);
        mFlMopi.setVisibility(visibleBeauty);
//        mFlWhitening.setVisibility(visibleBeauty);
        mFlWhitenTeeth.setVisibility(visibleBeauty);
        mFlLip.setVisibility(visibleBeauty);
//        mFlComplexion.setVisibility(visibleBeauty);
        mFlEyes.setVisibility(visibleBeauty);
        mFlHair.setVisibility(visibleBeauty);
        mFlBoobJob.setVisibility(visibleBoDy);
        mFlButtocks.setVisibility(visibleBoDy);
        mFlTail.setVisibility(visibleBoDy);
        mFlMaleAbs.setVisibility(visibleBoDy);
        mFlFamaleAbs.setVisibility(visibleBoDy);
        mFlPecs.setVisibility(visibleBoDy);
        mFlBicep.setVisibility(visibleBoDy);
    }

    public void selectFuntion(String type) {
        switch (type) {
            case HomeOnlineConfig.ACTION_BOBJOB:
                onClick(mBoobJobBt);
                break;
            case HomeOnlineConfig.ACTION_BUTTOCK:
                onClick(mButtocksBt);
                break;
            case HomeOnlineConfig.ACTION_FEMALE_ABS:
                onClick(mFemaleAbsBt);
                break;
            case HomeOnlineConfig.ACTION_PECS:
                onClick(mPecsBt);
                break;
            case HomeOnlineConfig.ACTION_MALE_ABS:
                onClick(mMaleAbsBt);
                break;
            case HomeOnlineConfig.ACTION_EYETUNER:
                onClick(mEyesBt);
                break;
            case HomeOnlineConfig.ACTION_GLOW:
//                onClick(mWhiteningBt);
                break;
            case HomeOnlineConfig.ACTION_HAIR_COLOR:
                onClick(mHairBt);
                break;
            case HomeOnlineConfig.ACTION_LIPSTICK:
                onClick(mLipBt);
                break;
            case HomeOnlineConfig.ACTION_HEALING:
                onClick(mRepairBt);
                break;
            case HomeOnlineConfig.ACTION_RETOUCH:
                onClick(mOneKeyBt);
                break;
            case HomeOnlineConfig.ACTION_BICEP:
                onClick(mBicepBt);
                break;
            case HomeOnlineConfig.ACTION_TALLER:
                onClick(mTailBt);
                break;
            case HomeOnlineConfig.ACTION_SMOOTH:
                onClick(mMopiBt);
                break;
            default:
        }
    }

    public int getCurId() {
        return mCurId;
    }

}
